问题描述
我有各种 css 基本上我想确定页面的每个部分使用什么样式表,例如我希望我的导航栏使用导航样式表,而页面的其余部分可以使用主样式表.有什么想法吗?
I have various css's basically I want to determine what stylesheet each section of the page uses, for example I want my navigation bar to use the navigation stylesheet where the rest of the page can use the main stylesheet. Any ideas?
推荐答案
您不能这样做.样式表适用于整个页面.您必须简单地使选择器足够具体,以便样式仅应用于预期元素.
You cannot do this. A stylesheet applies to the entire page. You must simply make your selectors specific enough so that styles are applied only to the intended elements.
在您的示例中,您可以将导航项放在
下.所有特定于导航的样式都应以 #nav
选择器开头,以确保它们不会意外应用于页面上的任何其他元素:
In your example, you might put your navigation items under a <ul id="nav">
. All of your navigation-specific styles should start with a #nav
selector, to make sure they aren't accidentally applied to any other elements on the page:
#nav li { color:#000; }
#nav li.active_item { color:#f00; }
/* etc */
这篇关于使不同的样式表适用于页面的不同区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!