aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/_colon_active/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/css/_colon_active/index.html')
-rw-r--r--files/zh-cn/web/css/_colon_active/index.html128
1 files changed, 128 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/_colon_active/index.html b/files/zh-cn/web/css/_colon_active/index.html
new file mode 100644
index 0000000000..1d09b7d141
--- /dev/null
+++ b/files/zh-cn/web/css/_colon_active/index.html
@@ -0,0 +1,128 @@
+---
+title: ':active'
+slug: 'Web/CSS/:active'
+tags:
+ - CSS
+ - Layout
+ - Web
+ - 伪类
+ - 参考
+ - 布局
+translation_of: 'Web/CSS/:active'
+---
+<div>{{CSSRef}}</div>
+
+<p><span class="seoSummary"><a href="/zh-CN/docs/Web/CSS">CSS</a> <strong><code>:active</code></strong> <a href="/zh-CN/docs/CSS/Pseudo-classes">伪类</a>匹配被用户激活的元素。</span>它让页面能在浏览器监测到激活时给出反馈。当用鼠标交互时,它代表的是用户按下按键和松开按键之间的时间。</p>
+
+<pre class="brush: css no-line-numbers notranslate">/* Selects any &lt;a&gt; that is being activated */
+a:active {
+ color: red;
+}</pre>
+
+<p><code>:active</code> 伪类一般被用在 {{HTMLElement("a")}} 和 {{HTMLElement("button")}} 元素中. 这个伪类的一些其他适用对象包括包含激活元素的元素,以及可以通过他们关联的{{HTMLElement("label")}}标签被激活的表格元素。</p>
+
+<p>这个样式可能会被后声明的其他链接相关的伪类覆盖,这些伪类包括 {{cssxref(":link")}},{{cssxref(":hover")}} 和 {{cssxref(":visited")}}。为保证样式生效,需要把 <code>:active</code> 的样式放在所有链接相关的样式之后。这种链接伪类先后顺序被称为 <em>LVHA 顺序</em>:<code>:link</code> — <code>:visited</code> — <code>:hover</code> — <code>:active</code>。</p>
+
+<div class="note"><strong>注意:</strong> 在有多键鼠标的系统中,CSS 3 规定 <code>:active</code> 伪类必须只匹配主按键;对于右手操作鼠标来说,就是左键。</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox notranslate">{{csssyntax}}</pre>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="激活链接">激活链接</h3>
+
+<h4 id="HTML">HTML</h4>
+
+<pre class="brush: html notranslate">&lt;p&gt;This paragraph contains a link:
+ &lt;a href="#"&gt;This link will turn red while you click on it.&lt;/a&gt;
+ The paragraph will get a gray background while you click on it or the link.
+&lt;/p&gt;</pre>
+
+<h4 id="CSS">CSS</h4>
+
+<pre class="brush: css notranslate">a:link { color: blue; } /* 未访问链接 */
+a:visited { color: purple; } /* 已访问链接 */
+a:hover { background: yellow; } /* 用户鼠标悬停 */
+a:active { color: red; } /* 激活链接 */
+
+p:active { background: #eee; } /* 激活段落 */</pre>
+
+<h4 id="结果">结果</h4>
+
+<p>{{EmbedLiveSample('Active_links')}}</p>
+
+<h3 id="激活表单元素">激活表单元素</h3>
+
+<h4 id="HTML_2">HTML</h4>
+
+<pre class="brush: html notranslate">&lt;form&gt;
+ &lt;label for="my-button"&gt;My button: &lt;/label&gt;
+ &lt;button id="my-button" type="button"&gt;Try Clicking Me or My Label!&lt;/button&gt;
+&lt;/form&gt;</pre>
+
+<h4 id="CSS_2">CSS</h4>
+
+<pre class="brush: css notranslate">form :active {
+ color: red;
+}
+
+form button {
+ background: white;
+}</pre>
+
+<h4 id="结果_2">结果</h4>
+
+<p>{{EmbedLiveSample('Active_form_elements')}}</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('HTML WHATWG', 'scripting.html#selector-active', ':active')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS4 Selectors', '#active-pseudo', ':active')}}</td>
+ <td>{{Spec2('CSS4 Selectors')}}</td>
+ <td>无更改。</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS3 Selectors', '#useraction-pseudos', ':active')}}</td>
+ <td>{{Spec2('CSS3 Selectors')}}</td>
+ <td>无更改。</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS2.1', 'selector.html#dynamic-pseudo-classes', ':active')}}</td>
+ <td>{{Spec2('CSS2.1')}}</td>
+ <td>无更改。</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS1', '#anchor-pseudo-classes', ':active')}}</td>
+ <td>{{Spec2('CSS1')}}</td>
+ <td>首次定义。</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("css.selectors.active")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>链接相关伪类:{{cssxref(":link")}}、{{cssxref(":visited")}} 和 {{cssxref(":hover")}}。</li>
+</ul>