1

I know the order of css selectors matters within a style sheet, but does the order of the references to external sheets matter?

I have a page that is referencing 2 sheets. One of the rules in the main sheet is overriding a rule in the other sheet. Rearranging the references hasn't helped. I don't know what to do.

2
  • Did you check that it's actually being overriden (using Firebug or similar?) Commented Sep 24, 2009 at 15:38
  • Please post a minimal test case. Commented Sep 24, 2009 at 15:41

3 Answers 3

4

whack an !important after the style you want to enforce.

Example:

p.my-style {
    color:#000;
    text-decoration:none !important;
}
Sign up to request clarification or add additional context in comments.

2 Comments

can you provide a sample? perhaps the style is not specific enough to the element.
I spoke too soon. That did help.
1

The !important clause following a property is the sure-fire way to have it take precedence over all others, however you can address it in a different way by understanding the selector's specificity. There's a great primer for the concept of CSS selector specificity here.

Essentially, you will want to make the selector which contains the property that you wish to "win" be much more specific by using ids and a more specific hierarchy of tags/classes/ids

Comments

0

The declaration order is used as a tie breaker when different rules have the same importance, origin (page author, user or user-agent) and specificity. Read section "6.4.1 Cascading order" of CSS 2.1 for details.

If a rule isn't applying, make sure the selector matches and is of equal or higher specificity than other selectors that match the same element. Examine the element in a good CSS debugger.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.