Aspect ratio divs with CSS background images

前端 未结 2 727
独厮守ぢ
独厮守ぢ 2020-12-22 00:41

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

2条回答
  •  死守一世寂寞
    2020-12-22 01:25

    You could try using view widths to keep the proportions on resize:

    HTML
    
    Here's a title
    Here's a title
    Here's a title
    CSS .hotels { display: inline-block; width: 31.8vw; height: 26.3vw; vertical-align: top; margin-bottom: 22px; background-image:url(http://www.telodesign.com/test/cavallo-300.jpg); background-size: cover; }

提交回复
热议问题