ID 选择器
在一个HTML文档中,CSS ID 选择器会根据该元素的 ID 属性中的内容匹配元素,元素 ID 属性名必须与选择器中的 ID 属性名完全匹配,此条样式声明才会生效。
/* The element with id="demo" */
#demo {
border: red 2px solid;
}
语法
示例
CSS
span#identified {
background-color: DodgerBlue;
}
HTML
<span id="identified">Here's a span with some text.</span>
<span>Here's another.</span>
结果
规范
规范 | 状态 | 备注 |
---|---|---|
Selectors Level 4 ID selectors |
Working Draft | |
Selectors Level 3 ID selectors |
Recommendation | |
CSS Level 2 (Revision 1) ID selectors |
Recommendation | |
CSS Level 1 ID selectors |
Recommendation | 初始定义 |
浏览器兼容性
BCD tables only load in the browser