【问题标题】:Why is there padding in table?为什么表格中有填充?
【发布时间】:2015-11-13 22:49:48
【问题描述】:

我正在制作一张桌子,虽然我没有添加任何填充,但表 1 中的一些 th(见小提琴)似乎有一个小的填充顶部。我该如何解决?

http://jsfiddle.net/6a1usq1s/

 <table id="table1">
<tr>
    <th>
        <div class="body-table">VersF)</div>
    </th>
    <th>
        <div class="h2-table">Drse</div>
        <div class="body-table subheading">son</div>
    </th>
    <th>
        <div class="h2-table">sne</div>
        <div class="body-table subheading">Sstz</div>
    </th>
    <th>
        <div class="h2-table">Br</div>
        <div class="body-table subheading">s</div>
    </th>
    <th>
        <div class="h2-table">a</div>
        <div class="body-table subheading">an</div>
    </th>
    <th>
        <div class="h2-table">a</div>
        <div class="body-table subheading">a</div>
    </th>
</tr>

【问题讨论】:

  • 这是默认样式。
  • 如果您说的是小写字母低于大写字母(从顶部开始)的显示,则它的行高和字母的性质。检查垂直对齐:w3schools.com/cssref/…
  • 不起作用:(在我的情况下,第一个字母都是大写的,只是在示例中没有;)

标签: html html-table padding


【解决方案1】:
vertical-align:top;

是解决方案:)

【讨论】:

    【解决方案2】:

    您可以尝试取消 tr 或 td 的填充以取消使用默认安装在浏览器中的样式:

    padding: 0;
    

    然后您可以为 div 或 tr/td 设置高度,并使用 line-height 属性来调节单元格中文本的提供(如果文本位于一行中)。如果 height 等于 line-height,则文本将垂直放置在中间。

    height: 20px;
    line-height: 20px;
    

    用这个属性做实验。

    【讨论】:

      猜你喜欢
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      • 2016-10-06
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 2020-12-16
      相关资源
      最近更新 更多