CSS如何进行分组和嵌套定义

作用

  • CSS 分组可以将具有相同样式的选择器进行分组,每个选择器用逗号分隔, 减少代码量。
  • CSS 嵌套适用于选择器内部的选择器的样式

代码示例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style>
p,h2
{
	color:blue;
	text-align:center;
}
.marked
{
	background-color:red;
}
.marked p
{
	color:yellow;
}
</style>
</head>

<body>
<p>This paragraph has blue text, and is center aligned.</p>
<div class="marked">
<h2>This paragraph has not blue text.</h2>
<p>p elements inside a "marked" classed element keeps the alignment style, but has a different text color.</p>
</div>

</body>
</html>
发布了63 篇原创文章 · 获赞 55 · 访问量 2474

猜你喜欢

转载自blog.csdn.net/devin_xin/article/details/105069664
今日推荐