<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>2.CSS常用选择器与优先级</title>
<style>
/* 标签选择器 */
h3{
background: red;
color: wheat;
}
/* 类class选择器 */
.bg-blue{
background: lightblue;
color: yellow;
}
/* id选择器 */
#bg-yellow{
background: yellowgreen;
}
</style>
</head>
<body>
<!-- 内联样式style属性优先级大于id选择器 -->
<h3 style="background-color:lightgreen;color:white">样式规则 = 选择器 + 声明</h3>
<hr>
<!-- id选择器大于class类选择器 -->
<h3 class="bg-blue" id="bg-yellow">样式规则 = 选择器 + 声明</h3>
</body>
</html>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号