CSS Priority

E

EYEBUZZ

Hello,

If you have a style sheet that is linked from an HTML document AND you have a
duplicate style sheet actually on the page, meaning some names are the same but
parameters are different, which takes priority (which does the browsers look
too for instruction)?

Does this change in different browsers/platforms?

Thanks,
Tim
 
D

Dylan Parry

EYEBUZZ said:
Hello,

If you have a style sheet that is linked from an HTML document AND you have a
duplicate style sheet actually on the page, meaning some names are the same but
parameters are different, which takes priority (which does the browsers look
too for instruction)?

Does this change in different browsers/platforms?

The last style defined always takes precedence, unless the !important
keyword is used, which just complicated issues :)

The general order is something like:

External author's CSS - ie. <link... />
Internal CSS - ie. within <style...></style>
Inline styles - ie. <span style="..."></span>
The user's own stylesheet

HTH
 
L

Leif K-Brooks

Dylan said:
The last style defined always takes precedence, unless the !important
keyword is used, which just complicated issues :)

Nonsense. A stylesheet can have this:

#bar {
color : red;
}
..foo {
color : blue;
}

And this will be red, even though blue was defined after red:

<div class="foo" id="bar">Red or blue, Neo?</div>
 
D

Dylan Parry

Leif said:
Nonsense. A stylesheet can have this:

#bar {
color : red;
}
.foo {
color : blue;
}

And this will be red, even though blue was defined after red:

<div class="foo" id="bar">Red or blue, Neo?</div>

If you read the OP and my reply you will see that I was not referring to
styles defined within the one sheet or to the complication of using a
class and an id in the same element, but to the general overview - the
last style being defined is the user's stylesheet, which takes precedence.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top