Css, Wrap Element Tightly Around Unspecified Number Of Images
I have an element that displays images. This element needs to grow horizontally with the number of images. I do not know beforehand how many images there will be. My problem is tha
Solution 1:
Add display:inline-block
to the container to shrink-to-fit, then add font-size:0
to collapse the surrounding whitespace: sample fiddle
Solution 2:
Set either display:inline-block
or float:left
on your outer div.
Float jsFiddle example
Inline-block jsFiddle example
Positioning them absolutely will also shrink wrap them but usually requires additional position rules (top, left, etc.).
Solution 3:
Use display: inline-block;
on both the outer and inner elements. Do you need to enforce a max-width?
HTML
<div class="outer">
<img src="http://www.bostonbakesforbreastcancer.org/wp-content/uploads/2012/03/sun.jpg" class="inner" />
<img src="http://www.bostonbakesforbreastcancer.org/wp-content/uploads/2012/03/sun.jpg" class="inner" />
<img src="http://www.bostonbakesforbreastcancer.org/wp-content/uploads/2012/03/sun.jpg" class="inner" />
</div>
CSS
.outer{
background: black;
display: inline-block;
padding: 10px 10px 5px 10px;
}
.inner {
background: yellow;
display: inline-block;
width: 50px;
}
Post a Comment for "Css, Wrap Element Tightly Around Unspecified Number Of Images"