CSS3 : Strange padding on bottom of an image

标签 css

有人可以解释一下为什么图像下方 有这个黄色的小填充吗?我知道图像右侧的黄色空间是正常的,但为什么在下方?知道如何解决这个问题吗?

谢谢!

http://jsfiddle.net/uu0dggmr/

HTML:

<body>

<div id="page">

    <div class="box">

        <div class="info" style="background:yellow">
        <img src="https://placehold.it/350x150" style="max-width:100%;height:auto">
        </div>

     <div class="info">Text</div>

</div>

<footer>Footer</footer>

</div>

</body>

CSS:

body{margin:0;font-size:100%}

#page{margin: 0 auto}

footer{background:black;color:white}

.box {background:white}
.info {background:orange}

@media screen and (min-width:480px) {

  .box {width:100%;float:left}
  .info {width:50%;float:left}

}

最佳答案

img 是一个行内元素,所以它考虑了行高。要避免图像下方的空间,您可以执行以下操作之一:

  • 在图片上设置float: left
  • 在图片上设置display: block
  • 在 .info div 上设置 line-height: 0

关于CSS3 : Strange padding on bottom of an image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32129524/

相关文章:

html - 网页布局问题

javascript - 如何避免 flex 元素在折叠时具有相同的高度

css - 如何在我的 Joomla 模板中将 2 个 span6 类堆叠在一起

css - 避免垂直对齐 : middle extending height of containing block

jQuery 切换 slider

jquery - 在 div 上应用 CSS 'fadeInDown' 动画会停止 jQuery 'Scroll to Fade' 在同一个 div 上工作

firefox - 如何将 anchor 标记编码为 block 元素以包含其他 block 元素

javascript - 图像 slider "previous"按钮无法正常工作

javascript - 仅在另一个 div 内跟随光标移动的 jQuery div

html - CSS left, position 和 floating ...在多个浏览器中的不同结果