Display image at 50% of its “native” size

前端 未结 5 858
野趣味
野趣味 2020-11-29 19:39

I\'m putting an img tag in a document without knowing the width/height of the corresponding image:


5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 20:06

    Set the image to be the background of a div, then set the background size to be half the width of the image.

    Then in your css, if your image is 300px x 200px:

    .myimage {
        background: url('images/myimage.png') no-repeat;
        background-size:150px;
        width:150px;
        height:100px;
    }
    

提交回复
热议问题