aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/universal_selectors/index.html
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/universal_selectors/index.html
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/universal_selectors/index.html')
-rw-r--r--files/zh-cn/web/css/universal_selectors/index.html142
1 files changed, 142 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/universal_selectors/index.html b/files/zh-cn/web/css/universal_selectors/index.html
new file mode 100644
index 0000000000..8b72901ccc
--- /dev/null
+++ b/files/zh-cn/web/css/universal_selectors/index.html
@@ -0,0 +1,142 @@
+---
+title: 通配选择器
+slug: Web/CSS/Universal_selectors
+tags:
+ - CSS
+ - Selectors
+ - 选择器
+translation_of: Web/CSS/Universal_selectors
+---
+<p>{{ CSSRef() }}</p>
+
+<h2 id="概述">概述</h2>
+
+<p>在CSS中,一个星号(<code>*</code>)就是一个通配选择器.它可以匹配任意类型的HTML元素.在配合其他简单选择器的时候,省略掉通配选择器会有同样的效果.比如,<code>*.warning</code> 和<code>.warning</code> 的效果完全相同.</p>
+
+<p>在CSS3中,星号(<code>*</code>)可以和命名空间组合使用:</p>
+
+<ul>
+ <li><code>ns|*</code> - 会匹配<code>ns</code>命名空间下的所有元素</li>
+ <li><code>*|*</code> - 会匹配所有命名空间下的所有元素</li>
+ <li><code>|*</code> - 会匹配所有没有命名空间的元素</li>
+</ul>
+
+<h2 id="Examples" name="Examples">示例</h2>
+
+<pre class="brush: css">*[lang^=en]{color:green;}
+*.warning {color:red;}
+*#maincontent {border: 1px solid blue;}
+</pre>
+
+<p>上面的CSS作用于下面的HTML:</p>
+
+<pre class="brush: html">&lt;p class="warning"&gt;
+ &lt;span lang="en-us"&gt;A green span&lt;/span&gt; in a red paragraph.
+&lt;/p&gt;
+&lt;p id="maincontent" lang="en-gb"&gt;
+ &lt;span class="warning"&gt;A red span&lt;/span&gt; in a green paragraph.
+&lt;/p&gt;
+</pre>
+
+<p>则会产生这样的效果:</p>
+
+<p><span style="color: rgb(0, 255, 0);">A green span</span><span style="color: rgb(255, 0, 0);"> in a red paragraph.</span></p>
+
+<p style="border: 1px solid blue;"><span style="color: rgb(255, 0, 0);">A red span</span><span style="color: rgb(0, 255, 0);"> in a green paragraph (with a border.)</span></p>
+
+<div class="note">注: 笔者不推荐使用通配选择器,因为它是<a class="external" href="http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/" title="http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/">性能最低的一个CSS选择器</a>.</div>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><a class="external" href="http://www.w3.org/TR/css3-selectors/#universal-selector" title="http://www.w3.org/TR/css3-selectors/#universal-selector">CSS Selectors Level 3</a></td>
+ <td>{{ Spec2('CSS3 Selectors') }}</td>
+ <td>定义了在命名空间下的行为并提示在伪元素中忽略它是允许的</td>
+ </tr>
+ <tr>
+ <td><a class="external" href="http://www.w3.org/TR/CSS21/selector.html#universal-selector" title="http://www.w3.org/TR/CSS21/selector.html#universal-selector">CSS 2.1</a></td>
+ <td>{{ Spec2('CSS2.1') }}</td>
+ <td>初始定义</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>
+
+<p>{{ CompatibilityTable() }}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{ CompatGeckoDesktop("1") }}</td>
+ <td>7</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ </tr>
+ <tr>
+ <td>Combination with namespace support</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{ CompatGeckoDesktop("1") }}</td>
+ <td>9</td>
+ <td>8</td>
+ <td>1.3</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatGeckoMobile("1") }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ </tr>
+ <tr>
+ <td>Combination with namespace support</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ <td>{{ CompatUnknown() }}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="相关链接">相关链接</h2>