Forum Moderators: not2easy

Message Too Old, No Replies

How exactly does inheritance work?

         

willamowius

3:36 pm on Feb 26, 2004 (gmt 0)

10+ Year Member



When I set a attribute on body, it is supposed to be passed on to eg. p.

Is there a chart or some kind of detailed explanation what is supposed to be inherited by which tag? Will p inherit from h1, or is inheritance based on the hierarchy of the actual document?

Thanks for any pointers!

HelenDev

3:52 pm on Feb 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there,

The way I understand it, is that if you use a rule on the body tag, everything in the body will inherit it. But if you also have rules for P, these will override the BODY rules. I don't think declaring a style on P will have any effect on H1.

There is some brief stuff about this on the webmonkey site

[hotwired.lycos.com...]

Helen.

DrDoc

3:58 pm on Feb 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Basically, children inherit from their parents.

p {
color: red;
}
div {
color: blue;
}
h1 {
color: green;
}

<p>
I am red
<span>I am also red</span>
</p>

<div>
<h1>Green here</h1>
I am blue
<p>
But I am red
<span>And so am I</span>
Still red...
</p>
Blue again
<span>Still blue</span>
</div>

4css

4:41 pm on Feb 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you DRDoc for your explaination as this is where I am also runing into problems. Mine tends to extend into when you have an ID and contextuals added to it.

ergophobe

7:56 pm on Feb 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




- When two rules conflict, specificity wins.

<html>
<head>
<style type="text/css">
body {color: blue;}
p {color: red;}
.green {color: green;}
#orange {color: orange;}
</style>
</head>

<body>

<h1>I'm blue</h1>

<p>I'm red</p>

<div class="green">
<h1>I'm green</h1>
<p>I'm still red</p>
</div>

<p class="green" id="orange">I'm orange</p>

</body>
</html>

Tom