diff options
Diffstat (limited to 'files/zh-cn/web/css/id_selectors/index.html')
| -rw-r--r-- | files/zh-cn/web/css/id_selectors/index.html | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/id_selectors/index.html b/files/zh-cn/web/css/id_selectors/index.html new file mode 100644 index 0000000000..41ae08f7b7 --- /dev/null +++ b/files/zh-cn/web/css/id_selectors/index.html @@ -0,0 +1,85 @@ +--- +title: ID 选择器 +slug: Web/CSS/ID_selectors +tags: + - CSS + - Selectors + - 参考 + - 选择器 +translation_of: Web/CSS/ID_selectors +--- +<div>{{CSSRef}}</div> + +<p>在一个HTML文档中,CSS ID 选择器会根据该元素的 ID 属性中的内容匹配元素,元素 ID 属性名必须与选择器中的 ID 属性名完全匹配,此条样式声明才会生效。</p> + +<pre class="brush: css no-line-numbers">/* The element with id="demo" */ +#demo { + border: red 2px solid; +}</pre> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">#id属性值 {<var>样式声明</var> }</pre> + +<p>它与下面的{{Cssxref("Attribute selectors", "属性选择器")}}语句等价:</p> + +<pre class="syntaxbox">[id=id属性值] {<var>样式声明</var> }</pre> + +<h2 id="示例">示例</h2> + +<h3 id="CSS">CSS</h3> + +<pre class="brush: css">span#identified { + background-color: DodgerBlue; +} +</pre> + +<h3 id="HTML">HTML</h3> + +<pre class="brush: html"> <span id="identified">Here's a span with some text.</span> + <span>Here's another.</span> +</pre> + +<h3 id="结果">结果</h3> + +<p>{{EmbedLiveSample("Example", '100%', 50)}}</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("CSS4 Selectors", "#id-selectors", "ID selectors")}}</td> + <td>{{Spec2("CSS4 Selectors")}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("CSS3 Selectors", "#id-selectors", "ID selectors")}}</td> + <td>{{Spec2("CSS3 Selectors")}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("CSS2.1", "selector.html#id-selectors", "ID selectors")}}</td> + <td>{{Spec2("CSS2.1")}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName("CSS1", "#id-as-selector", "ID selectors")}}</td> + <td>{{Spec2("CSS1")}}</td> + <td>初始定义</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("css.selectors.id")}}</p> |
