【问题标题】:Is text-align not possible for <col> tag? <col> represents the group of column in <colgroup> [duplicate]<col> 标签不能进行文本对齐吗? <col> 表示 <colgroup> 中的列组 [重复]
【发布时间】:2014-04-26 03:51:08
【问题描述】:

这个特殊的 html 代码是创建一个有两行两列的表格,并将第一列背景装饰为红色,并将第二列文本右对齐。遇到的非常有趣的事情是对齐没有发生,为什么?

<table>
  <colgroup>
    <col style="background-color:red">
    <col style="text-align:right">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
  </tr>
</table>

【问题讨论】:

    标签: html css


    【解决方案1】:

    使用 nth-child 代替。正如评论中的问题所提到的,文本对齐不适用于 col 或 colgroup 标签。

    http://jsfiddle.net/f2ue4/1/

    td:nth-child(2),
    th:nth-child(2) {
        text-align: right;
    }
    

    【讨论】:

      【解决方案2】:

      Jsfiddle DEMO

      body > table > tbody > tr > th
      {
          text-align:right;
      }
      

      您需要为表头指定第标签

      【讨论】:

        猜你喜欢
        • 2019-08-24
        • 2017-06-06
        • 2011-09-13
        • 1970-01-01
        • 2018-04-10
        • 2012-06-14
        • 2011-05-29
        • 2017-07-15
        • 1970-01-01
        相关资源
        最近更新 更多