Load images based on screen size

前端 未结 7 1833
臣服心动
臣服心动 2020-12-14 23:23

I have the following HTML code which displays an image:

\"PP\"
7条回答
  •  情歌与酒
    2020-12-14 23:58

    Use a media query to shrink the image and show a background image.

    Note: this method requires you know the size/proportions of the replacement image.

    Fiddle

    PP
    
    @media screen and (max-width:568px) {
      #wm01 {
        background: url("theImages/wm01_app.jpg") no-repeat 0 0;
        height: 0;
        width: 0;
        padding-bottom: 300px; /* replace with height of wm01_app.jpg */
        padding-right: 300px; /* replace with width of wm01_app.jpg */
      }
    }
    

提交回复
热议问题