/* 示例代码 */
/* 优先级从高到低排列 */
/* 1. 行内样式 (直接在HTML标签中定义的style属性) */
<p style="color: red;">行内样式的优先级最高</p>
/* 2. ID选择器 (#id) */
#myId {
color: blue;
}
/* 3. 类选择器 (.class)、属性选择器 ([attribute]) 和伪类选择器 (:hover) */
.myClass {
color: green;
}
/* 4. 标签选择器 (element) 和伪元素选择器 (::before, ::after) */
p {
color: black;
}
/* 5. 通用选择器 (*) 和子选择器 (>), 相邻兄弟选择器 (+) 等 */
* {
margin: 0;
padding: 0;
}
style属性,优先级最高。#id的形式,优先级次之。如果需要更复杂的优先级计算,可以参考每个选择器的权重值。
上一篇:style.css
下一篇:css作用
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站