Why does a <h2> inside a <h1> not inherit the value of color property?

sunaiwen

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?

Jon

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么<h1>中的<h2>不继承color属性的值?

来自分类Dev

style h1 inside a div

来自分类Dev

HTML如何使H1,H2等作为链接?

来自分类Dev

列出所有h1,h2

来自分类Dev

XSLT 2.0:从线性<h1 />-<h2 />-<h3 />标签系统构建树

来自分类Dev

JAWS和“真实语义标头”(h1,h2,h3)

来自分类Dev

XPath:获取最接近的标题元素(h1,h2,h3等)

来自分类Dev

XSLT 2.0:从线性<h1 />-<h2 />-<h3 />标签系统构建树

来自分类Dev

XPath:获取最接近的标题元素(h1,h2,h3等)

来自分类Dev

添加标题 h1、h2、h3 (Contempo)

来自分类Dev

如何创建可以用作h1,h2,h3,h4..etc的版式组件

来自分类Dev

如何创建可以用作h1,h2,h3,h4..etc的版式组件

来自分类Dev

使用PHP将大写的H1,H2,...标签转换为大写标题

来自分类Dev

如何在jello布局中将h1,h2对齐到中心?

来自分类Dev

使用execCommand切换H1和H2

来自分类Dev

h1标记小于h2,全部包含部分标记

来自分类Dev

为<h1> <h2>等以外的所有文本设置字体大小

来自分类Dev

是否最好将id属性放在“ a”标签或“ h1 / h2”标签中?

来自分类Dev

如何抓取<h1> <h2>并保存到VBScript中的文本文件

来自分类Dev

部分应该以h1还是h2开头?

来自分类Dev

如何使<h1>标头保持在<h2>标头的顶部?

来自分类Dev

HTML标题有长度限制吗?(h1,h2等)

来自分类Dev

使用execCommand切换H1和H2

来自分类Dev

SEO H2标签放在H1上方,这有关系吗?

来自分类Dev

我可以给H1和H2设置相同的字体大小吗

来自分类Dev

使用PHP将大写的H1,H2,...标签转换为大写的标题

来自分类Dev

在h1成因下的.entry-content中添加h2

来自分类Dev

很难将h1和h2与CSS对齐

来自分类Dev

在同一个类中设置h1和h2的样式

Related 相关文章

热门标签

归档