开发者

Correct CSS inheritance behavior for properties that aren't inherited?

开发者 https://www.devze.com 2022-12-31 17:17 出处:网络
So say we you have a CSS property that is not inherited by default. We\'ll call it \"foo\" and its default value is \"black\". Then we make the following html.

So say we you have a CSS property that is not inherited by default. We'll call it "foo" and its default value is "black". Then we make the following html.

<div id="div1" style="foo: red;">
 <div id="div2">
   <div id="div3" style="foo: inherit;">
   </div>
 </div>
</div>

Since this property does not inherit by default, you'd think that in div2, "foo" must be "black" - the default value because it does not inherit by default.

But ... in div3 should the value for "foo" inherit "black" from its parent that did not inherit foo, or should i开发者_StackOverflow中文版t inherit "red" from its grandparent because its parent did not specify foo?

I need to know because I'm trying to implement something exactly to the spec.


It inherits its parent's (not grandparent's) computed value: http://www.w3.org/TR/CSS2/cascade.html


div3 will inherit from div2, so its foo will be black. inheritance is from the parent.

0

精彩评论

暂无评论...
验证码 换一张
取 消