简体   繁体   English

将外部样式表分配给html中的特定表

[英]Assigning external stylesheet to specific table in html

我可以在单个页面中为多个表中的特定表分配外部CSS样式表吗?

style.css style.css

#someid{
    color: red;
}

HTML 的HTML

<head>
    <link rel="stylesheet" href="style.css" type="text/css" />
</head>

...

<table id="someid">
    ...
</table>

Yes. 是。 You can do it. 你能行的。 However using more than one style-sheets is not good from a performance perspective. 但是,从性能的角度来看,使用多个样式表是不好的。 If you know that you are NEVER going to change your CSS code once you have built it then single style-sheet is best for you. 如果您知道一旦构建CSS代码就永远不会更改它,那么单个样式表最适合您。 Multiple style-sheet are good if you are going to change your CSS once in while and you need to keep it easily manageable/updateable. 如果您要偶尔更改CSS,并且需要使其易于管理/更新,则多个样式表是不错的选择。

To assign external stylesheet to a specific table: 要将外部样式表分配给特定表:

1.First assign a css class name or css id name (for example I am using class name "table-with-external-SS") to your table in your html page code as below: 1.首先在您的html页面代码中为您的表格分配一个CSS类名称或CSS ID名称(例如,我正在使用类名称“ table-with-external-SS”),如下所示:

<table class="table-with-external-SS">
<thead>
..............
..............
..............
</table>

2.Then create an external stylesheet which target only this table's class.Write css to target only the table with class for eg ".table-with-external-SS" as following: 2.然后创建一个仅针对该表的类的外部样式表。编写css以仅针对具有类的表,例如“ .table-with-external-SS”,如下所示:

table.table-with-external-SS {
    color: navy;
    background-color: cyan;
}

3.Save this by any name for example mystylesheet.css. 3.使用任何名称保存此名称,例如mystylesheet.css。 Then link this stylesheet in you html code in head section as below: 然后在您的html代码的头部部分中链接此样式表,如下所示:

<head>
<link rel="stylesheet" type="text/css" href="mystylesheet.css">
</head>

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM