Automatically resize images with browser size using CSS

前端 未结 4 775
感情败类
感情败类 2020-11-27 12:07

I want all (or just some) of my images getting resized automatically when I resize my browser window. I\'ve found the following code - it doesn\'t do anything though.

<
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 12:43

    To make the images flexible, simply add max-width:100% and height:auto. Image max-width:100% and height:auto works in IE7, but not in IE8 (yes, another weird IE bug). To fix this, you need to add width:auto\9 for IE8.

    source: http://webdesignerwall.com/tutorials/responsive-design-with-css3-media-queries

    for example :

    img {
        max-width: 100%;
        height: auto;
        width: auto\9; /* ie8 */
    }
    

    and then any images you add simply using the img tag will be flexible

    JSFiddle example here. No JavaScript required. Works in latest versions of Chrome, Firefox and IE (which is all I've tested).

提交回复
热议问题