Html 在表格或 div 中轻松设置所有 Td 的样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11036395/
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
Easy styling of all Td's in a table or in a div
提问by Wilson
Is there a way I can use one category to stylize all of my table cells? I cant just use
有没有一种方法可以使用一个类别来风格化我的所有表格单元格?我不能只是使用
td{
}
because I have another table on the same page that I don't want the same style on. The table I want to stylize has around 40 cells, so is there a way to collectively style them short of copy-pasting a class or id 40 times?
因为我在同一页面上有另一个表格,我不想要相同的样式。我想要风格化的表格有大约 40 个单元格,所以有没有办法在不复制粘贴类或 id 40 次的情况下对它们进行集体设计?
回答by Lowkase
Put a selector on the table tag:
在 table 标签上放置一个选择器:
<table class="my-special-table">
<tr><td></td></tr>
</table>
table.my-special-table td { style it up! }
回答by Ben Roux
If your table has a specific attribute such an as ID, you can reference it in CSS specifically:
如果你的表有一个特定的属性,比如 ID,你可以在 CSS 中专门引用它:
<table id="myStyledTable">
<tr>
<td>...
Like so:
像这样:
#myStyledTable td {
}
回答by Waqar Alamgir
Use this:
用这个:
#table-id td {
/* some css */
}
回答by cssviking
Or #table-id > tr > td { /* some css */ } in case you will have other tables within this table that shouldn't have this style applied.
或者 #table-id > tr > td { /* some css */ } 以防您在该表中还有其他不应应用此样式的表。
回答by eric.itzhak
You can give an id/class to that table and do :
您可以为该表提供一个 id/class 并执行以下操作:
#yourtable td { }
回答by jeffmcneill
Either an id or a class will allow it to be individually styled as:
一个 id 或一个类将允许它被单独设置为:
<table class="myclass">
or
或者
<table id="myid">
and then
进而
.myclass td {}
or
或者
#myid td {}
respectively.
分别。