Forum Moderators: not2easy

Message Too Old, No Replies

Turn off inheritance?

Is there any way to do it?

         

MatthewHSE

2:41 am on Oct 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm finding it would be very handy to be able to set some CSS classes so that their "children" do NOT inherit the values. Is there any way to do that?

Thanks,

Matthew

BlobFisk

9:35 am on Oct 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think so - inheritance is one of the strengths of CSS.

You will need to explicitly restyle the elements or create a new class.

MatthewHSE

1:56 pm on Oct 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's kind of a pity. I know inheritance is one of the main strengths of CSS like you said, but there are times when it would be nice to turn it off. Seems that something like this:

inheritance: no-inherit

. . . could be a good CSS option, which would cause that class not to be inherited. Or maybe better would be something like this:

body {
text-align: center;
[font-weight: bold];
}

Where anything [between square brackets] isn't inherited.

The reason I was wondering about this is that I just found out that IE5 won't center a div where the left and right margins are set to auto. So I set the text-align to center for the body of the document - which was then inherited by everything and all my text was centered. I've found ways around this, but they're tending toward code-bloat and it's getting more complex than I would have liked. So I was just hoping inheritance could be turned off (for certain classes or portions of classes) if desired.

Well, enough of me trying to teach the W3C. If anyone happens to know of a way that inheritance can be turned off after all, please let me know!

Thanks,

Matthew

DrDoc

2:40 pm on Oct 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only reason why you would want to turn off inheritance is to compensate for buggy browsers...
That's why we can't do it...

CSS wasn't meant to provide support for crappy <cough style="read: IE;" /> browsers ;)

SuzyUK

2:43 pm on Oct 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Matthew it can't be turned off.. it's the C in CSS it just won't go away ;) hehe

you should be able to overrule this scenario quite easily though as you just need to set text-align: back to left on the first child of the body (1 line of code only if you have a container div in place).. then everything goes back to normal

this is an(other) IE5 browser issue and I'm afraid its them you have to blame for the code bloat in this instance, but at least it's only CSS code and not HTML bloat...

I don't think the W3C will change a standard just for it.. but I don't blame you for trying....

Suzy
<added>hehe Doc.. great minds ...</added>

MatthewHSE

2:58 pm on Oct 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're both right, I suppose. Come to think of it I can't think of another instance where inheritance would NOT be a benefit. You're solution is beautifully simple, SuzyUK, and I'll be implementing it in just a minute. Glad you brought it up before I changed my whole CSS file!

I'm so tired of coding for IE; I remember when I was first starting in with web design about ten months ago IE was all I coded for. I'll say one thing for it; it's buggy enough to handle buggy code with no problem!

Then I started trying to write strict code and validate it. After a couple weeks of getting used to that, I found out just how buggy ALL versions of IE really are. It got to be far more difficult to write IE-compatible code than it was to write code that Mozilla would display properly. Personally I don't think MS is all that interested in web standards anyway . . . they'd rather be the standard than comply with it.

DrDoc

3:51 pm on Oct 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sad thing is that they think they are the standard :(