making different syle sheets apply to different areas of the page
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 st开发者_运维问答ylesheet 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.
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 */
Either use iframes, or use css classes. Remember, css classes can be combined:
<div class="class1 class2 and-so-on">...</div>
Therefore you can use one stylesheet which only targets class1, one which only targets class3... and import all your stylesheets normally.
If your CSS is not too huge, you should combine it in one file. This will improve your download speed and make it easier on the user.
If you would like to keep the styles separate, use comments in your CSS, e.g.
#######NAV STYLES######
.nav li {something:something;}
.nav li a {something:something;}
######MAIN STYLES######
#main #wrapper {something:something;}
If you wanted to seperate out your css to make it easier to manage. You could separate your css into seperate files and call the using @import url();
. For example:
core.css would be like so:
//Navigation styles
@import url("navigation.css");
//Banner styles
@import url("banner.css");
//Footer styles
@import url("footer.css");
This would however create one style sheet, which includes the separate referenced ones.
This is not possible, since the CSS apply to the entire page. To achieve what you want, you should divide your page into different sections, by giving a unique ID to each section for example. This way you can apply separate styles to separate sections of your page.
For example your navigation div could have id="navigation-bar"
, then in the CSS you will write:
#navigation-bar {
/* styles here will apply only to navigation-bar and elements inside it */
}
And so on...
精彩评论