css几种选择器与优先级实践:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS常用选择器与优先级</title>
<style>
h3 {
background-color: antiquewhite;
color: azure;
}
/* 类选择器 用.表示*/
.bj {
background-color: blueviolet;
color: brown;
}
/* id选择器,用#号表示 */
#yellow {
background-color: black;
color: #000;
}
</style>
</head>
<body>
<h3>样式规则,选择器,声明,属性</h3>
<h3 class="bj">样式规则,选择器,声明,属性</h3>
<h3 class="bj" id="yellow">样式规则,选择器,声明,属性</h3>
<!-- 选择器层面:标签小于class,.小于id,style级别最高 -->
<!-- 内联样式style优先级大于id -->
</body>
</html>点击 "运行实例" 按钮查看在线实例
css选择器:标签直接调用,class,id,style等;其中class可用“.”表示,id的用“#”表示。
优先级:style最高,其次是id、class、标签。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号