Owl Carousel Auto Width with margin not working - css

I have a fixed height on all my images and need to keep the image in proportion as the screen width gets smaller.
#owl-demo .item img {
display: block;
width: auto;
height: 300px
}
This works fine until I need to put a margin in between the images.
#owl-demo .item {
margin:0 10px 0 10px;
}
The margin won't show and the images are side by side still. The margin will show if I put width: 100%
#owl-demo .item img {
display: block;
width: 100%;
height: 300px
}
But then the image is no longer in proportion.
I tried with Owl's own demo and this is the case. If you inspect one of the images and change it to the code at the top with width: auto you will see the margin no longer works. You will need to remove the max-width: 100% from the img tag from bootstrap also.
http://owlgraphic.com/owlcarousel/demos/images.html

Looks like you're using version 1.3.X
Try upgrading to version 2 and you'll be fine.

Related

Responsive image parent width not resizing

I have a row of responsive images set to 100% height and auto width wrapped in divs with a flexible height. The problem is the width of the parent divs is not changing reliably on browser resize, leaving gaps or overlaps in chrome and ie.
<div><img></div>
<div><img></div>
div {
display: inline-block;
height: 30vh;
background-color: #f3f;
}
img {
height: 100%;
width: auto;
}
https://jsfiddle.net/kyucun6b/1/
This is for my portfolio so people will definitely be resizing the browser, otherwise I probably wouldn't worry about it. Thanks.
The answer in the end was so simple I can't believe it took so long to discover. If you move the height to the images and give them a display: block it works as desired and the parent div resizes perfectly.
div {
display: inline-block;
background-color: #f3f;
}
img {
height: 30vh;
display: block;
width: auto;
}
https://jsfiddle.net/kyucun6b/5/

Slider Responsiveness

My web theme has a slider built in that wasn't full width. I did some research and to make it full width I added a 1400px wide image and set the containers css to:
width: 100%;
padding-right: 0px;
padding-left: 0px;
However it doesn't scale to smaller screen sizes like I was hoping. I did some research but can't find anything that works or is that specific. How do you think I can fix this and make it look the same on all screens.
instead of width set max-width
body {
margin: 0
}
div {
max-width: 1400px;
margin: auto;
}
img {
max-width: 100%
}
<div>
<img src="//placehold.it/1400x900" />
</div>

CSS Responsive Images either max-width or max-height

I'm currently working on my very first responsive webdesign working with Bootstrap 3.
What I now have is a full-width grid of user profile images. These images have a parent container which must be fully filled by the image. The parent container must have a fixed height because of the requested layout.
The problem is: Using CSS I only know how to fit either the width or the height, not depending on the size of the container.
You can see the problem in this jsfiddle:
http://jsfiddle.net/usD2d/
li /* container */ {
display: block;
overflow: hidden;
float: left;
width: 25%;
height: 100px; /* something fixed */
}
li img {
width: 100%;
min-height: 100%; /* destroys aspect ratio */
}
If you have a large screen, the images will fit perfectly. Having smaller devices the images will lose their aspect ratio.
Surely I could use #media(min-width) and change the img from width to height, but due to using BootStrap and having a very dynamic layout (collapsing sidebar, etc) this could become very tricky.
Is there any CSS only solution? If not, is there a great jQuery solution maybe also providing a focus point where to keep the focus on when cropping?
Thank you very much in advance!
If you want to fill entire space with image clipping it, ratio will be preserved but image will be partially hidden. vertical-align and negative margin can be used.
example: http://jsfiddle.net/usD2d/2/ keeping center image in center(like would a background-position: center center ;.
ul {
width: 100%;
}
li {
display: block;
float: left;
width: 24%;
height: 150px;
overflow: hidden;
border: 1px solid black;
text-align:center;/* set image in center */
line-height:150px;/* set image or text right in middle;*/
}
img {
min-width: 100%;
vertical-align:middle;/* okay see it in middle , but you can tune this */
margin:-50% -100%; /* okay, you can tune margin to crop/clip other area */
}
the negative margin reduce virtually size of image wich will center(text-align ) and sit on baseline set by line-height.
This a CSS cropping.
I think that you want the image to determine the width of the <li>. I removed the width: 25%; property, and your images kept their aspect ratio in your fiddle. So change
li /* container */ {
display: block;
overflow: hidden;
float: left;
width: 25%;
height: 100px; /* something fixed */
}
to
li /* container */ {
display: block;
overflow: hidden;
float: left;
height: 100px; /* something fixed */
}

DIV width: 100% creates a space when is the window resize to a size less than major DIV

I got a div #header width: 1000px;
#header {
width: 1000px;
margin: auto;
height: 164px;
}
A div #main-container in full-width
#main-container {
height: 278px;
background: url(images/mainbg.png);
width: 100%;
}
But when I resize my window to a size less than 1000px setted on header, the #main-container creates a empty space.
http://tinypic.com/view.php?pic=1zcmmpf&s=5
I want to remove this space, and let the #main-container have full-width
What you are seeing is correct CSS behavior.
For example, consider your HMTL snippet:
<div id="header"></div>
<div id="main-container"></div>
with the following CSS:
body {
margin: 0;
}
#header {
width: 1000px;
margin: auto;
height: 164px;
background-color: yellow;
}
#main-container {
height: 278px;
background: pink url('http://placekitten.com/2000/278') top center no-repeat;
width: 100%;
}
See demo at: http://jsfiddle.net/audetwebdesign/5xwRu/
For pages wider than 1000px, your header is centered as you expect.
Your background image fills up width of the page because the #main-container has 100% width.
As you reduce the page width to less than 1000px, you will see a horizontal scrolling bar appear because the fixed width header is too wide to fit in the view port, which triggers
an overflow condition.
In this situation, the CSS engine creates some white space the right of #main-container since #main-container has a computed width less than 1000px and it fills up the view port width (which is less than 1000px), which does not include the space created for the overflowing content.
You can fix this a number of ways, but it depends in part on what you want to do.
You could set a minimum width as follows:
#main-container {
height: 278px;
background: pink url('http://placekitten.com/2000/278') top center no-repeat;
width: 100%;
min-width: 1000px;
}
See example 2 in the demo fiddle.
Note: You may have a wrapper container to which the CSS property overflow: hidden is applied. If this is the case you may not see a horizontal scrolling bar.

Only first image stays in view when browser size decreases

I have a series of images laid across horizontally in a div.
The goal is that as the browser gets smaller, so do the images, so they are all visible and stay inline.
Currently, only the first image will stay visible, while the other images go out of view. (Although all of the images to get smaller.
Here is the JSFiddle: http://jsfiddle.net/KXGUM/
You will notice that one you make your browser smaller, the images will get smaller but only the first one will stay in view, the others you have to scroll right to see.
I want all of them to still be visible, meaning they all have to shrink together.
CSS:
body{margin: 0 auto;}
#week-wrap {border: 1px solid #000; height: auto; white-space: nowrap; max-width: 100%; width: auto; }
img {max-width: 100%; height: auto; display: inline-block; width: auto;}
Since you got 3 images their width should be 33% of the parent container.
Change your 100% in 33% and they're all on the screen and in one line.
img {max-width: 33%; height: auto; display: inline-block; width: auto;}
See here: http://jsfiddle.net/KXGUM/1/

Resources