开发者社区> 问答> 正文

表格如何定义列样式的文本属性

如代码所示,可以对列的背景色进行改变,但是修改文本对齐方式和文本颜色就不起作用了,能解决吗?
html

<table>
    <colgroup>
        <col />
        <col />
        <col class="right" />
    </colgroup>
    <tr>
        <td>aaa</td>
        <td>bbb</td>
        <td>ccc</td>
    </tr>
    <tr>
        <td>aaa</td>
        <td>bbb</td>
        <td>ccc</td>
    </tr>
    <tr>
        <td>aaa</td>
        <td>bbb</td>
        <td>ccc</td>
    </tr>
</table>​
css

table {
    width: 100%;
}
td {
    border: 1px solid #999;
}
.right {
    background: green;
    color: #fff;
    text-align: right;
}

展开
收起
a123456678 2016-03-24 16:07:11 2103 0
1 条回答
写回答
取消 提交回答
  • IE的IE7和Quirks模式下,文本颜色和对齐方向都可以正常设置
    IE8(含)以上以及其他浏览器均不支持。

    CSS具体样式对col和colgroup支持的细节,我找到如下说法:

    The style attribute (or induced style from id, class, etc.) only takes into account properties that sensibly apply to the column itself. That is, while each

    can contain text content and thus can have attributes like text-align set, the element does not contain text and thus none of the text-level styles apply. (Block-level stuff like background-color still works.)
    意思就是 col 元素不包含文本,所以被指定的有关于文本级别的样式是不会被应用的。
    2019-07-17 19:12:58
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载