SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Canada, Ontario
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Css ... Importance? Overriding? Im unsure what to ask!

    Hey guys,

    I think this would be a fairly common question however I dont know what to search for...

    I have additions for a future website, which currently links to css files (2-3 depending on the page):

    <link rel="stylesheet" type="text/css" title="cc" media="screen" href=......
    <link rel="stylesheet" type="text/css" title="cc" media="screen" href=......

    Etc...

    I cannot change these files. They must be linked to in my files, and I have the need to override some tags (h3, h2 etc) that are existant in these files. If I link to a css file after the current linked css files, does that css file have more importance? What happens if one of the things I need to override is marked as important?

    If someone could just show me what to search for (I tried importance) or give a quick suggestion or link it would be greatly appreciated.

  2. #2
    SitePoint Addict Sojan80's Avatar
    Join Date
    May 2002
    Location
    Central WI, US
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe that the last rule applied/enountered should have precedence.

    depending of course on how the rule is brought in. By this I mean if you link to several stylesheets and then in an h3 on your page you put in some local style rules h3 style='color: blue;' that ar placed in a style tag within the element itself this rule will override the other rule contained in the linked stylesheet.

  3. #3
    SitePoint Wizard bronze trophy Tailslide's Avatar
    Join Date
    Feb 2006
    Location
    Bedford, UK
    Posts
    1,687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to write rules to apply site-wide that will overrule the 2/3 existing stylesheets then you could add all of these "new" rules into another stylesheet and list it last - after the other 2 or 3 existing ones. The last stylesheet listed will have precedence over the others.

    If you can't add another external stylesheet then you could use embedded CSS in the head of each page. This will have precedence over all linked stylesheets but obviously only applies to a single page.

    If you can't do that then you could use inline CSS within the relevant HTML tag itself which would have precedence over both linked and embedded CSS. This is the least flexible solution and I wouldn't advise it in general.

    The order of precedence is:

    Inline CSS takes precedence over
    Embedded CSS which takes precedence over
    Linked External stylesheets (last in the list of stylesheets takes precedence where there are more than one)
    Little Blue Plane Web Design
    Blood, Sweat & Rust - A Land Rover restoration project

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Canada, Ontario
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great thanks for you help!

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Canada, Ontario
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "order of precedence" is was I was trying to think of!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •