CSS中class中的空格有什么意义?

html-css013

CSS中class中的空格有什么意义?,第1张

class中的空格是为了给html标签同时赋予多个class类名。

在使用类选择器之前,需要修改具体的文档标记,以便类选择器正常工作。

为了将类选择器的样式与元素关联,必须将 class 指定为一个适当的值。请看下面的 HTML 代码:

<h1 class="important">This heading is very important. </h1><p class="important">This paragraph is very important. </p>

在上面的代码中,两个元素的 class 都指定为 important:第一个标题( h1 元素),第二个段落(p 元素)。

扩展资料:

例如:如果希望将一个特定的元素同时标记为重要(important)和警告(warning),就可以写作:<p class="important warning">This paragraph is a very important warning. </p>这两个词的顺序无关紧要,写成 warning important 也可以。

假设 class 为 important 的所有元素都是粗体,而 class 为 warning 的所有元素为斜体,class 中同时包含 important 和 warning 的所有元素还有一个银色的背景 。

空格代表包含关系。

.ne_area .festival_wrap .snow5 的意思是: .ne_area包含.festival_wrap,而.festival_wrap又包含.snow5,就像下面这样:

<div class="ne_area">

<div class="festival_wrap">

<div class="snow5"></div>

</div>

</div>

最终css的样式将会作用在最里面的那个div上(即<div class="snow5"></div>)