HTML:如何使用不同的 CSS 制作 2 个表格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7992198/
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
HTML: how to make 2 tables with different CSS
提问by michelemarcon
I want to put two tables (on the same page) which should render differently (i.e. use different CSS for each table). Is it possible?
我想放置两个表格(在同一页面上),它们应该以不同的方式呈现(即为每个表格使用不同的 CSS)。是否可以?
回答by Jon Egerton
In your html
在你的 html
<table class="table1">
<tr>
<td>
...
</table>
<table class="table2">
<tr>
<td>
...
</table>
In your css:
在你的 css 中:
table.table1 {...}
table.table1 tr {...}
table.table1 td {...}
table.table2 {...}
table.table2 tr {...}
table.table2 td {...}
回答by thandasoru
You need to assign different classes to each table.
您需要为每个表分配不同的类。
Create a class in CSS with the dot '.' operator and write your properties inside each class. For example,
在 CSS 中创建一个带有点“.”的类。运算符并在每个类中写入您的属性。例如,
.table1 {
//some properties
}
.table2 {
//Some other properties
}
and use them in your html code.
并在您的 html 代码中使用它们。
回答by Sahil Muthoo
Of course, just assign seperate css classes to both tables.
当然,只需将单独的 css 类分配给两个表。
<table class="style1"></table>
<table class="style2"></table>
.css
.css
table.style1 { //your css here}
table.style2 { //your css here}
回答by Widor
Of course it is!
当然是这样!
Give them both an id
and set up the CSS accordingly:
给他们一个id
并相应地设置CSS:
#table1
{
CSS for table1
}
#table2
{
CSS for table2
}
回答by David Horák
<table id="table1"></table>
<table id="table2"></table>
or
或者
<table class="table1"></table>
<table class="table2"></table>