如何摆脱容器元素的额外高度? 请参阅示例代码中第一张图片下方的蓝色条纹
div {
background-color: blue;
display: inline-block;
}
<div>
<img src="https://lh5.googleusercontent.com/-8ryRirhRs5o/VEOv3vaXt7I/AAAAAAAAKSU/xBB9lnkn35Y/s144/BGDragonNGlare.jpg">
</div>
<img src="https://lh5.googleusercontent.com/-8ryRirhRs5o/VEOv3vaXt7I/AAAAAAAAKSU/xBB9lnkn35Y/s144/BGDragonNGlare.jpg">
答案 0 :(得分:2)
将display:block;
添加到img
。
div {
background-color: blue;
display: inline-block;
}
div img{
display: block;
}
&#13;
<div>
<img src="https://lh5.googleusercontent.com/-8ryRirhRs5o/VEOv3vaXt7I/AAAAAAAAKSU/xBB9lnkn35Y/s144/BGDragonNGlare.jpg">
</div>
<img src="https://lh5.googleusercontent.com/-8ryRirhRs5o/VEOv3vaXt7I/AAAAAAAAKSU/xBB9lnkn35Y/s144/BGDragonNGlare.jpg">
&#13;