现在的位置: 首页 > 综合 > 正文

CSS多类选择器

2014年06月25日 ⁄ 综合 ⁄ 共 541字 ⁄ 字号 评论关闭

在HTML里,一个class值中可能包含一个词列表,各个词之间用空格分隔。

例如,如果希望将一个特定的元素同时标记为重要(important)和警告(warning)。就可以写作

<p class="important warning">
This paragraph is a very important warning.
</p>

注意:

1 这俩个类的顺序无关紧要。

2 我们假设class为important的所有元素都是粗体。class为warning的所有元素为斜体。

  class中同时包含important和warning的所有元素还有一个银色的背景。

  就可以写成

.important {font-weight:bold;}
.warning {font-style:italic;}
.important.warning {background:silver;}

注意:

如果一个多类选择器包含类名列表里没有的一个类名(urgent),匹配就会失败。

.important.urgent {background:silver;}

不过他能匹配一下元素:

<p class="important urgent warning">
This paragraph is a very important and urgent warning.
</p>


【上篇】
【下篇】

抱歉!评论已关闭.