CSS image resize percentage of itself?

前端 未结 11 2101
执念已碎
执念已碎 2020-11-28 20:46

I am trying to resize an img with a percentage of itself. For example, I just want to shrink the image by half by resizing it to 50%. But applying width: 50%; w

11条回答
  •  無奈伤痛
    2020-11-28 21:33

    This actually is possible, and I discovered how quite by accident while designing my first large-scale responsive design site.

    .wrapper { position:relative; overflow:hidden; } .box { float:left; } //Note: 'float:right' would work too .box > img { width:50%; }

    The overflow:hidden gives the wrapper height and width, despite the floating contents, without using the clearfix hack. You can then position your content using margins. You can even make the wrapper div an inline-block.

提交回复
热议问题