Using More Than One Stylesheet

Discussion in 'CSS' started by gobbly2100, Aug 6, 2007.

  1. #1
    If I want to use more than one stylesheet how do I go about doing that?

    I have this in the header so far:
    <link rel="stylesheet" type="text/css" href="main.css" />
     
    gobbly2100, Aug 6, 2007 IP
  2. Skinny

    Skinny Peon

    Messages:
    1,864
    Likes Received:
    93
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Skinny, Aug 6, 2007 IP
  3. twistedspikes

    twistedspikes Notable Member

    Messages:
    5,694
    Likes Received:
    293
    Best Answers:
    0
    Trophy Points:
    280
    #3
    put in the same thing but linking to another stylesheet:

    The one on the bottom will take prioroty over the one on the top, it's just as if the css was added onto the bottom of the first document.

    <link rel="stylesheet" type="text/css" href="style.css" />
    <link rel="stylesheet" type="text/css" href="hacks.css" />
     
    twistedspikes, Aug 8, 2007 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    <style type="text/css" media="all">
    @import url(styles1.css);
    @import url(styles2.css);
    @import url(styles3.css);

    </style>
     
    Danltn, Aug 9, 2007 IP
  5. twistedspikes

    twistedspikes Notable Member

    Messages:
    5,694
    Likes Received:
    293
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Bad way to do it.
     
    twistedspikes, Aug 9, 2007 IP
  6. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #6
    <link /> to one stylesheet, and @import others inside (typography, forms, etc). I find it's easier to split a few into sections.

    Some might say it will really slow your site down because of the extra HTTP requests, but I say it makes it much easier to develop if you're doing upgrades often.
     
    soulscratch, Aug 9, 2007 IP
  7. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Never had to use more than one stylesheet, but thanks for the heads up.
     
    Danltn, Aug 12, 2007 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    Not necessarily - For example if you have a standard library of styles (like say some non-image corner code) that would only be linked into your screen.css and not your print.css, @import can be handy to link that in.

    But then I actually name any CSS that will be linked directly into my page by their media type (finding style.css or main.css just a little vague) or media type plus page name for page specific stuff.

    For example the second page of my non-image corner code tutorial:

    http://battletech.hopto.org/html_tutorials/rounded_css_borders/more_styles.html

    get's this in it's HTML to link in the common screen stylesheet from the first page.

    <link rel="stylesheet" type="text/css" href="screen.css" media="screen, projection" />
    <link rel="stylesheet" type="text/css" href="screen_morestyles.css" media="screen, projection" />

    While screen.css calls the screen_borderstyles.css thus:

    @import "screen_borderstyles.css";

    Since all pages in that section are going to use the borderstyles I import that as a 'library' to screen.css - but since only the second page needs screen_morestyles.css I inline that one in that page's HTML.

    Both methods have their place.
     
    deathshadow, Aug 12, 2007 IP
  9. AdamSee

    AdamSee Well-Known Member

    Messages:
    422
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    135
    #9
    The @import rule can be useful for graceful degradation of older browsers, such as IE4 and below. From memory @import '/stylesheet.css'; stops a majority of browsers below IE 5 from reading the stylesheet. Many people will not need to adhere to such strict standards, but it's good to know. Be careful not to fouc up.
     
    AdamSee, Aug 12, 2007 IP
  10. bryandy

    bryandy Peon

    Messages:
    774
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #10

    agreed, why do u wana use 2 style sheets?
     
    bryandy, Aug 12, 2007 IP
  11. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #11
    Maybe just wants to use different media types? Maybe including CSS that only effects one page that overrides the default styles from the rest of the pages? Maybe modularize some standard CSS for all your different websites for re-use?

    There are reasons to do it - like any other tool the key is not to OVERUSE it. (see tables, DIV's, etc)

    Though FOUC is MUCH more common when you use javascript sniffing to output the CSS code - though yes it is a concern particularly if your CSS is overly large and does not compensate for measurements 'top-down'.

    Though using javascript or conditionals to determine which CSS to use is definately a bit #DDD
     
    deathshadow, Aug 12, 2007 IP