Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

ID选择器

概述

在一个HTML文档中,CSS ID 选择器会根据该元素的ID属性中的内容匹配元素,元素ID属性名必须与选择器中的ID属性名完全匹配,此条样式声明才会生效。

语法

#id属性 {样式声明 }

注意它与下面的语句等价 attribute selector:

[id=id属性] {样式声明 }

示例

span#identified {
  background-color: DodgerBlue;
}

上面的CSS作用于下面的HTML代码:

  <span id="identified">Here's a span with some text.</span>
  <span>Here's another.</span>

则会产生下面的效果:

Here's a span with some text.
Here's another.

规范

Specification Status Comment
CSS Selectors Level 3 Recommendation  
CSS 2.1 Recommendation  
CSS 1 Recommendation  

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ? ?

See also

文档标签和贡献者

标签: 
 此页面的贡献者: fscholz, teoli, alimon
 最后编辑者: fscholz,