html - 为什么要覆盖 css 类?

标签 html css

我有一张 table 。我只希望第一列左对齐,其他列右对齐。我使用以下样式:

<style>
    table{ width:100%;}
    .1col{ text-align:left;}
    .othercols{width:100px;}
    table>tbody>tr>td, table>tbody>tr>th { text-align:center;} 
</style>

然后我有我的 table :

<table>
    <tr>
        <th class="1col">Category</th>
        <th class="othercols">Some text</th>
        <th class="othercols">Some text</th>
        <th class="othercols">Some text</th>
    </tr>
    <tr >
        <td class="1col">Some text</td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</table>

结果是我的 1col 类被忽略了。有什么想法吗?

最佳答案

CSS 类不能以整数开头,因此请尝试使用 col1

工作示例:http://jsfiddle.net/9X7kz/8/

如果你有兴趣,这里是完整的语法:

http://www.w3.org/TR/CSS21/grammar.html#scanner

这是具体的规则规范:

http://www.w3.org/TR/CSS21/syndata.html#characters

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".

关于html - 为什么要覆盖 css 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11965173/

相关文章:

html - 我无法使用 css 设置表格的上边距

javascript - 代码在 codepen 上有效,但在我的网站上无效

javascript - document.body.style 是什么奇怪的对象

javascript - Polymer DOM-根据接收到的数据重复内容

html - 如何使用条件选择页面CSS的所有类元素

javascript - 更改内容可编辑的 div 文本时如何保留插入符位置?

html - css3自适应图像绝对位置

css - 选择的 jquery 插件中的垂直滚动问题

Javascript/jQuery 更改内联样式值

html - Bootstrap 下拉菜单在轮播幻灯片中不起作用