首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ID选择器 | ID selectors

在HTML文档中,CSS ID选择器根据其id属性的值匹配元素。所选元素的ID属性必须与选择器中给定的值完全匹配。

代码语言:javascript
复制
/* The element with id="demo" */
div#demo {
  border: red 2px solid;
}

语法

代码语言:javascript
复制
#id_value { style properties }

请注意,这相当于以下内容attribute selector

代码语言:javascript
复制
[id=id_value] { style properties }

实例

CSS

代码语言:javascript
复制
div#identified {
  background-color: skyblue;
}

HTML

代码语言:javascript
复制
<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)

?

?

?

?

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com