我想为所有标题应用一种格式。
所以,我补充说
.myformat h1, h2, h3, h4, h5, h6 { margin-bottom : 1em; ... }
这么写的,不考虑第一个
hx
.这些规则不适用于 h1。当我写成这样
.myformat h1, h2, h3, h4, h5, h6, h1 { margin-bottom : 1em; ... }
一切安好。这些规则适用于 h1、h2、... 和 h6。
这很可疑……我想我在其他地方有问题,但我看不到它。
将规则应用于多个选择器是正确的方法吗?
我在窗口上的 IE9 和 Chrome20 上有相同的行为。也在 Fedora15 上的 Firefox12 上复制
编辑
我希望能够做类似的事情
<h1 class="myformat">This text will be red and
or all hx where I apply "myformat"
</h1>
<p class="myformat">This text will be yellow only
when myformat is applied on a paragraph
</p>
我创建了
.myformat h1, h2, h3, h4, h5, h6 { margin-bottom : 1em; ... }
相信这个“myformat”只会应用于标题。我是来创造的
.myformat p { margin-bottom : 3em; ... }
但我屏蔽了 <h1 class="myformat">text</h1>
最佳答案
像这样尝试 .myformat h1、.myformat h2、.myformat h3 等。
这是假设 h1 的 h2 的 h3 都在一个名为 .myformat 的 div 中。
您可以在这里查看:http://jsfiddle.net/fYgdA/5/
关于css - 如何将一个规则应用于多个选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11731338/