为同一网页的不同部分应用不同的CSS样式表 [英] Apply different css stylesheet for different parts of the same web page
问题描述
我有一个网页,有不同的部分,需要不同的CSS样式表应用于每个。我想知道的是如何指定要使用的网页的每个不同部分的CSS样式表。
您不能将不同的样式表应用于不同的部件的页面。您有以下几个选项:
最好是用div名称将div的不同部分包装在div中:
< div class ='part1'>
....
< / div>
< div class ='part2'>
....
< / div>然后在你的part1 CSS中,每个CSS规则前缀为.part1,在你的part2 CSS中,前缀每个CSS规则与.part2。注意,通过使用类,您可以使用多个不同的part1或part2div,以灵活划分页面的哪些部分受到哪些CSS规则的影响。
I have a web page with different parts which require different css stylesheets to be applied to each. What I would like to know is how to specify which css stylesheet to use for each different part of the web page. if I leave them all together, the components do not get displayed properly.
解决方案 You can't apply different stylesheets to different parts of a page. You have a few options:
The best is to wrap the different parts of the page in divs with class names:
<div class='part1'>
....
</div>
<div class='part2'>
....
</div>
Then in your part1 CSS, prefix every CSS rule with ".part1 " and in your part2 CSS, prefix every CSS rule with ".part2 ". Note that by using classes, you can use a number of different "part1" or "part2" divs, to flexibly delimit which parts of the page are affected by which CSS rules.
这篇关于为同一网页的不同部分应用不同的CSS样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!