Html CSS 特定表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11286897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:22:52  来源:igfitidea点击:

CSS specific table

htmlcsscss-tables

提问by John Doe

I have an HTML document where I have two different tables. One is class Alpha and one is class Beta. I want to assign this css to class Beta only...

我有一个 HTML 文档,其中有两个不同的表格。一种是 Alpha 级,一种是 Beta 级。我只想将此 css 分配给 Beta 类...

td
{
border-style:solid;
border-top:thick double #ff0000;
}

I can not figure out how to assign this only to Beta. Does anyone know how?

我不知道如何仅将其分配给 Beta。有谁知道怎么做?

回答by brezanac

Just apply the .betaclass selector to the entire table and change your CSS code to apply a rule only to tddecedents of .betalike this:

只需将.beta类选择器应用于整个表格并更改您的 CSS 代码以仅将规则应用于这样的td死者.beta

<table class="beta">
    <tr>
        <td>...</td>
        <td>...</td>
    </tr>
</table>
.beta td {
    border-style:solid;
    border-top:thick double #ff0000;
}

If you need to apply the rule to multiple elements within .betasimply add an additional selector like this:

如果您需要将规则应用于多个元素,.beta只需添加一个额外的选择器,如下所示:

.beta td, 
.beta th {
    border-style:solid;
    border-top:thick double #ff0000;
}

Qapla'!

卡普拉'!

回答by John Conde

CSS lets you get specific with what elements rules are to be applied to. Just add this rule to the table.Beta td cell declaration and you're done.

CSS 可让您具体了解要应用哪些元素规则。只需将此规则添加到 table.Beta td 单元格声明中即可。

table.Beta td 
{
    border-style:solid;
    border-top:thick double #ff0000;
}