如果下面代码
<p style="height: 100px; overflow: scroll" >
<img src="img" style="height: 200px; />
</p>
请问如何让img总是居中,尤其是img的height比p 的height还大,image还是居中。
因为p的overflow是scroll的所以图片的上部和下部看不见,但是 p里面显示的还是图片的中部。请从css角度思考。
谢谢
黄舟2017-04-17 11:07:24
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>
ringa_lee2017-04-17 11:07:24
If img is longer than p
1. Set img width as percentage
2. Set text-align of p: center
PHP中文网2017-04-17 11:07:24
If you have problems with centering, you can try flex box It’s so simple.