Look at this simple example:
<style>
h1 {
color: red;
}
</style>
<h1>this is the 'h1'.<h2>this is the 'h2'</h2></h1>
I expected the color of the string within the 'h2' to be red, but it is still black.
This has confused me for a while. Why does it happen?
An <h1>
element is not permitted to contain <h2>
elements (among others; only phrasing elements and text are permitted), so according to the spec that is invalid HTML.
The browser tries to compensate for the invalid HTML by considering that the <h2>
is actually outside the <h1>
, which leads to the observed result.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句