I have images of equal aspect ratios (300px x 255px) in divs taking up ~31% of the width to make 3 columns on desktop/tablet, then full width on mobile. The images scale to 100% within the div, with the height set as auto. I need to change them from img tags to background images
http://codepen.io/anon/pen/yYagJd
**HTML:**
<div class="hotels">
<img src="http://www.telodesign.com/test/cavallo-300.jpg" alt=""><br>
Here's a title
</div>
<div class="hotels">
<img src="http://www.telodesign.com/test/cavallo-300.jpg" alt=""><br>
Here's a title
</div>
<div class="hotels">
<img src="http://www.telodesign.com/test/cavallo-300.jpg" alt=""><br>
Here's a title
</div>
**CSS:**
.hotels {
display: inline-block;
width: 31.8%;
vertical-align: top;
margin-bottom: 22px;
}
*emphasized text*.hotels img {
width: 100%;
height: auto;
}
Is there a way to make these images background images, and still have the aspect ratio dictate the height of the div--allowing the same responsive scaling? I'm hoping there's a way to do this without using .js, if possible. Can it be done with just CSS? Thanks!
You could use % to set a padding taking width for reference to keep ratio. example : http://codepen.io/anon/pen/vNXgJp or http://codepen.io/anon/pen/VvKPMM (demos below)
or
You could try using view widths to keep the proportions on resize: