Forum Moderators: not2easy

Message Too Old, No Replies

Overriding a linked css

         

samblake

10:19 am on Jul 26, 2005 (gmt 0)

10+ Year Member



I have a number of classes defined in a linked style sheet. Is there a way to allow another linked style sheet to contain the same classes but will allow them to be overreidden if you understand what I mean. Thanks.

-Sam

abbeyvet

10:36 am on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can link to two style sheets - the second one, if it uses any of the same classes, will override anything that is in the first.

Is that what you mean?

samblake

10:37 am on Jul 26, 2005 (gmt 0)

10+ Year Member



Yeah, but what if I didn't have control over which one was the second one loaded?

Span

10:55 am on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In control or not, the second one, if it uses the same classes, will still override the first one loaded.

Welcome to the forums, samblake.

SuzyUK

11:14 am on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi samblake and Welcome..

First method is you have which you could use is the Cascade, if you don't have control over which stylesheet would be loaded first then you can embed styles into the head of a particular page or use inline styles.. the nearer the style rule is to the HTML element it applies to the more authority it has (i.e. it will override).

Another way if you can't control the order of styles is loaded first then using specificity might also help you:

html body h1#header {color: #f00;}

would overide

h1#header {color: #00f}

no matter which order the stylesheets (or rules in a single stylesheet) are in because the first rule is using much more selectors making it more specific. Specificity [w3.org] used together with identifying body id's or classes can give control of singular pages, regardless of the cascade.

Suzy

samblake

11:25 am on Jul 26, 2005 (gmt 0)

10+ Year Member



Thanks a lot Suzy, that's what I needed :).

samblake

2:06 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Also, couldn't it be done by marking a class as!important? Then the class amrked!important would override any class by the same name not marked as!important? I've never used!important before however so I may have got this wrong.

SuzyUK

6:38 pm on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sam..

I don't use !important much either except in user stylesheets for FF and Opera, as far as I remember that is becasue IE/Win (all versions?) and some other earlier browsers do not honour it.. so possibly best not relying on that method?

Suzy