Reputation: 1495
I have a bootstrap website that loads content dynamically from a database and lazyload's the images using this jQuery plugin - LazyLoad
It uses a placeholder, which is a white square png. Before the image loads (while the placeholder is visible) the image container looks how I want it to, and when the image has fully loaded it looks good too. However while the image is loading the layout collapses like so:
Is there a way to set the height of the image container to match the width? With it being a responsive site the width will change depending on the resolution. If that makes sense?
<div class='col-xs-6 col-sm-3 col-md-3'>
<div class='thumbnail'>
<a href='my_url.html'><img class = 'lazy' data-original='http://external.png' alt='product_name'></a>
<div class='caption' style = 'text-align: center;'>
<div style = 'height: 60px;'>product_name<br />
£product_price</div>
<p style = 'padding-top: 10px;'><a href='my_url.html' class='btn btn-primary btn-thumbp' role='button'>View</a> <a href='#' class='btn btn-default btn-thumbd' role='button'>Wishlist</a></p>
</div>
</div>
</div>
Upvotes: 2
Views: 948
Reputation: 6154
A pure CSS responsive solution is possible by taking advantage of the fact that the padding-top
percentages refer to the width of the element.
.thumbnail {
outline: solid 1px blue;
width: 250px; /* Any width */
}
.image {
width: 100%;
display: inline-block;
position: relative;
outline: solid 1px red;
}
.image:after {
padding-top: 100%;
display: block;
content: '';
}
Here's a short demo: http://jsbin.com/lohoxa/5/edit
Upvotes: 1