html - css 选择器查询

标签 html css

这是一小段代码。

<style ...>
h1 { color: red }
h2 { color: olive }
em { color: red }
h1 em { color: blue }
</style ...>

<body>
<H1>This <h2>headline is <EM>very</EM> important</h2> to me.</H1>
</body>

我什至在 jsfiddle 上试过这段代码,但不明白为什么最后两个词 to me 显示为黑色。我以为它会是红色的。

最佳答案

那是因为你不能嵌套 h1-h6 标签。 <h2>标签隐式关闭 <h1>所以它被解释为:

<body>
<H1>This </H1><h2>headline is <EM>very</EM> important</h2> to me.
</body>

关于html - css 选择器查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5146123/

相关文章:

javascript - 使用 Javascript 将单元格附加到集合

css - 尝试在一个容器内对齐 3 个图像 - 是否存在 float 问题?

html - 带照片的 Bootstrap 轮播 : optimal image size?

html - Bootstrap CSS Accordion 不会在二级页面上折叠

javascript - HTML5 本地存储不存储密码框中的值

javascript - 菜单中的输入框位置错误

html - nth-of-type 选择了错误的元素

javascript - 根据可用镜像添加、删除 "Active"类 bootstrap carousel

css - 不能在 iframe 中设置 Facebook 共享按钮的样式吗?

CSS 显示 :content not working in Safari