开发者

How do I retain the aspect ratio of an image if its dimensions are percentages?

My images have a 16:9 aspect ratio. I would like each image's wi开发者_开发技巧dth to be 33% of the entire browser window so I can stack 3 images per row:

[ ] [ ] [ ]
[ ] [ ] [ ]
[ ]

When I specify width:33% in CSS, the height does not change to maintain the 16:9 aspect ratio. Apparently, CSS is unlike HTML. In HTML, only one dimension needs to be specified.


Just add height: auto.. Thus:

img {
     width: 33%;
     height: auto;
}

Then the height adjusts itself according to the width.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜