aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/_colon_has
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/css/_colon_has
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/css/_colon_has')
-rw-r--r--files/zh-cn/web/css/_colon_has/index.html62
1 files changed, 62 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/_colon_has/index.html b/files/zh-cn/web/css/_colon_has/index.html
new file mode 100644
index 0000000000..ad784814b6
--- /dev/null
+++ b/files/zh-cn/web/css/_colon_has/index.html
@@ -0,0 +1,62 @@
+---
+title: ':has'
+slug: 'Web/CSS/:has'
+tags:
+ - CSS
+ - Pseudo-class
+ - Reference
+ - Selectors
+translation_of: 'Web/CSS/:has'
+---
+<div>{{CSSRef}}</div>
+
+<p><strong><code>:has()</code> </strong>CSS<strong> </strong><a href="/zh-CN/docs/Web/CSS/Pseudo-classes">伪类</a>代表一个元素,其给定的选择器参数(相对于该元素的 {{cssxref(":scope")}})至少匹配一个元素。</p>
+
+<p><code>:has()</code><strong> </strong>伪类接受一个选择器组作为参数。在当前规范中 <code>:has</code> 并未列为<a href="https://drafts.csswg.org/selectors/#live-profile">实时选择器配置</a>的一部分,意味着其不能用于样式表中,只能用于如 {{domxref("document.querySelector()")}} 的函数中。</p>
+
+<pre><code>/* 选择任何直接包含 &lt;img&gt; 子元素的 &lt;a&gt; */
+/* 注意,目前还没有任何浏览器支持此方法 */
+/* 此伪类也未计划投入样式表中使用 */
+var test = document.querySelector('a:has(&gt; img)');</code></pre>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox">{{CSSSyntax}}</pre>
+
+<h2 id="Examples" name="Examples">示例</h2>
+
+<p>下面的选择器只会匹配直接包含 {{HTMLElement("img")}} 子元素的 {{HTMLElement("a")}} 元素:</p>
+
+<pre><code>a:has(&gt; img)</code>
+</pre>
+
+<p>下面的选择器只会匹配其后紧跟着 {{htmlelement("p")}} 元素的 {{HTMLElement("h1")}} 元素:</p>
+
+<pre><code>h1:has(+ p)</code></pre>
+
+
+
+<h2 id="规范">规范</h2>
+
+<table>
+ <thead>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">注释</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{ SpecName('CSS4 Selectors', '#relational', ':has()') }}</td>
+ <td>{{ Spec2('CSS4 Selectors') }}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>
+
+<p>{{Compat("css.selectors.has")}}</p>
+
+<div id="compat-mobile"></div>