ID选择器
定义和用法
- #id指定具有id的元素。使用#来选择具有包含特定值的ID的元素。
- id值的名称必须紧跟在#后面。
- id通常在HTML文档中是唯一的。
- ID 选择器可能是区分大小写的。这取决于文档的语言。HTML 和 XHTML 将类和 ID 值定义为区分大小写,所以类和 ID 值的大小写必须与文档中的相应值匹配。
语法:
E#myid{sRules}
以文档目录树(DOM)中作为对象的唯一标识符的ID作为选择符。
浏览器支持
![]() | ![]() | ![]() | ![]() | ![]() |
所有浏览器都支持 |
例子
<h1 id="page-title">This is important!</h1> <ul id="example">This is important!</ul> h1#page-title {font-size: 250%;} #example{background: lime;}
<p id="firstname">This is a paragraph of introduction.</p> #firstname { background-color:yellow; }