CSS参考手册
选择 | Selectors
ID选择器 | ID selectors
在HTML文档中,CSS ID选择器根据其id
属性的值匹配元素。所选元素的ID
属性必须与选择器中给定的值完全匹配。
/* The element with id="demo" */
div#demo {
border: red 2px solid;
}
语法
#id_value { style properties }
请注意,这相当于以下内容attribute selector
:
[id=id_value] { style properties }
实例
CSS
div#identified {
background-color: skyblue;
}
HTML
<div id="identified">This div has a special ID on it!</div>
<div>This is just a regular div.</div>
结果
规范
Specification |
Status |
Comment |
---|---|---|
Selectors Level 4The definition of 'ID selectors' in that specification. |
Working Draft |
|
Selectors Level 3The definition of 'ID selectors' in that specification. |
Recommendation |
|
CSS Level 2 (Revision 1)The definition of 'ID selectors' in that specification. |
Recommendation |
|
CSS Level 1The definition of 'ID selectors' in that specification. |
Recommendation |
Initial definition |
浏览器兼容性
Feature |
Chrome |
Edge |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari |
---|---|---|---|---|---|---|
Basic support |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
Feature |
Android |
Chrome for Android |
Edge |
Firefox Mobile (Gecko) |
IE Mobile |
Opera Mobile |
Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support |
? |
? |
(Yes) |
? |
? |
? |
? |
选择 | Selectors相关
层叠样式表( Cascading Style Sheets )是一种用来表现 HTML 或 XML 等文件样式的计算机语言。CSS 不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。