Forum Moderators: not2easy

Message Too Old, No Replies

Overriding Style Sheet

A:Link

         

Shuvi

2:13 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



In my main style sheet that I include on all pages I have a formatting for the links, but on some of my pages I want to override that. How do I do that?
I have tried!Important But it did not work.

MWpro

3:29 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



You can either make a new class for it with the separate styles or you can simply use an inline style to override it. If you do not know how to do either of these two, respond and we can help you in further detail.

Shuvi

3:37 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



thank you!

bruhaha

3:42 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



If you wish to override the style for all links on the page, you may include the style in the head section after the link to your main style sheet. For that matter, you could include the style in a separate stylesheet, and list the link to it after the link to the main style sheet.

The order is important here--rules read last take precedence. Your "new" style rules should override the old ones.

mattr555

12:15 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



If you set the ID of your BODY tag on each page, you can then target elements on each page in the style sheet:

body#page1 a{color:red;}

body#page2 a{color:blue;}

If you only want to target links in an area of you page, enlose them in a DIV and use:

div#divname a{color:green;}

bruhaha

2:27 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



If you set the ID of your BODY tag on each page, you can then target elements on each page in the style sheet

This could be a very helpful solution, though I'll admit at first glance your example made me think it could be quite cumbersome, requiring a long list of ID's (one for each page, or at least each page that differed from the default style(s)).

But, in fact, since the ID selector can be used once per page, you should be able to reuse the same ID across many pages, and use a very limited number. In that case I would think you would want to avoid a pattern like "#page1,#page2, etc" and use something more generic.

I'm wondering, though...would that make it any different from using CLASS? And is there any reason you could not simply assign the style(s) to a CLASS and use that in a BODY tag on some pages, and in a block tag (e.g., DIV) on other pages, as needed?

(Theoretically, it seems that should work. But does the BODY tag accept the CLASS selector? And if it does, why do we create DIV blocks that include an entire page when we could accomplish the same thing in the BODY tag?)

encyclo

2:48 pm on Mar 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But does the BODY tag accept the CLASS selector?

Yes, the body tag can have a class applied to it, no problem. In this case, I agree with you that a class attribute would be more appropriate.

And if it does, why do we create DIV blocks that include an entire page when we could accomplish the same thing in the BODY tag?

Because people don't realise the above! Divs are generally over-used and make for bloated code, and can often be removed and the styles applied to other tags.