首页 > 解决方案 > 应用选择器的顺序有什么区别

问题描述

任务是为课堂上的所有段落设置红色standart

我是这样做的

.standart p { color:red; }

但有人告诉我这是不好的解决方案,这是“好的解决方案”

p.standart { color:red; }

这两者有什么区别?

标签: htmlcss

解决方案


.standart p { color:red; }
p.standart { color:red; }
<div class="standart">
<p>One</p>
<p>Two</p>
<p>Three</p>
</div>
<hr/>
<p class="standart">One 1</p>
<p class="standart">Two 2</p>
<p class="standart">Three 3</p>

. 标准 p { 颜色:红色;} 表示您想要标准类中所有段落的红色文本。

p.standard {颜色:红色;} 意味着你想要所有具有标准类的段落的红色文本。


推荐阅读