html - 神秘的表行填充/边距

标签 html css css-tables

我遇到一个问题,我可以在表格行上看到一些我不需要的神秘填充/边距,但无法删除。

请参阅下面用蓝色框突出显示的区域的屏幕截图:

enter image description here

代码在这里:

https://codepen.io/mattsmith/pen/GWZNVN

我尝试了很多东西,例如 margin: 0border-spacing: 0padding: 0 等。有人可以帮忙吗我在这儿吗?因为我需要蓝色框与图像齐平。

最佳答案

img内联元素“替换内容”,它将继承line-height,并且您将看到 line-height间距。您可以通过在父级上使用 line-height: 0;font-size: 0; 或设置 display: block; 来修复此问题> 或图像上的vertical-align: top

* {
  font-family: Open Sans;
}

table {
  border: 1px solid #000;
}

th {
  border: 1px solid red;
  vertical-align: top;
  font-weight: normal;
}

p {
  margin: 0;
}
img.banner {
  /* or either of these */
  /* display: block; */
  /* vertical-align: top; */
}
<body style="padding: 50px; background: #f7faf9">
<table style="border-collapse: collapse; margin: 0 auto; margin-top: 20px; width: 100%; max-width: 800px;">
  <tr>
    <th><img style="float: left; width: 70px" src="http://i.imgur.com/LsRs9OY.png"></th>
    <th><p style="text-align: right; font-size: 14px">February 14, 2017<br>Order <b>#4020</b></p></th>
  </tr>
  <tr>
    <th style="padding-top: 25px; line-height: 0;" colspan="2"><img style="width: 100%" class="banner" src="https://s3.amazonaws.com/zcom-media/sites/a0i0L00000QylPjQAJ/media/mediamanager/media_page_banner.jpg"></th>
  </tr>
    <tr>
    <th style="background: #35a0c6; padding-top: 25px;" colspan="2"></th>
  </tr>
</table>
</body>

关于html - 神秘的表行填充/边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42565848/

相关文章:

css - 文本周围的奇怪填充使包含的 div 太大

javascript - Angular 检查数组是否包含具有特定变量值的对象

javascript - 从 xml 文件创建 html5 播放列表

javascript - jQuery:fadeOut() 与 html(),奇怪的行为

html - 左浮动在我的页脚中不起作用,因此它无法正确显示内联

jquery - HTML 选项卡控件

小部件的CSS屏蔽

html - 如何调整列的大小以适合其文本宽度而不是所有列的宽度相同

jquery - 在 css div 表上使用 jQuery 扩展表行

html - 控制表格单元格之间的间距