前端 - 如何让img在div居中,img比div还长
阿神
阿神 2017-04-17 11:05:24
0
5
1122

如果下面代码

<p style="height: 100px; overflow: scroll" >
    <img src="img" style="height: 200px; />
</p>

请问如何让img总是居中,尤其是img的height比p 的height还大,image还是居中。
因为p的overflow是scroll的所以图片的上部和下部看不见,但是 p里面显示的还是图片的中部。请从css角度思考。

谢谢

阿神
阿神

闭关修行中......

reply all(5)
黄舟

Your code always looks awkward. Take a closer look at the colon ":" in the first line. Is it a Chinese colon? There is also a quotation mark missing in the style of the second line? That's why the third line is highlighted. It looks like there are problems...

Show picture:

<p style="height: 100px; overflow: hidden;  width:100px" >
    <img src="img" style="height: 200px; width:200px; margin-top: -100px; margin-left: -100px;" />
</p>
左手右手慢动作

If img is longer than p
1. Set img width as percentage
2. Set text-align of p: center

洪涛

If you have problems with centering, you can try flex box It’s so simple.

伊谢尔伦

Negative comments mixed styles are written in the tags 嘤嘤嘤

Ty80

Hahahaha your answer is so funny!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template