aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/_colon_focus
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_focus
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_focus')
-rw-r--r--files/zh-cn/web/css/_colon_focus/index.html96
1 files changed, 96 insertions, 0 deletions
diff --git a/files/zh-cn/web/css/_colon_focus/index.html b/files/zh-cn/web/css/_colon_focus/index.html
new file mode 100644
index 0000000000..fe3ae14c56
--- /dev/null
+++ b/files/zh-cn/web/css/_colon_focus/index.html
@@ -0,0 +1,96 @@
+---
+title: ':focus'
+slug: 'Web/CSS/:focus'
+tags:
+ - CSS
+ - Layout
+ - Reference
+ - Web
+ - 伪类
+translation_of: 'Web/CSS/:focus'
+---
+<p>{{CSSRef}}</p>
+
+<p>CSS<a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">伪类</a> <code>:focus</code>表示获得焦点的元素(如表单输入)。当用户点击或触摸元素或通过键盘的 “tab” 键选择它时会被触发。</p>
+
+<pre class="brush: css">/* Selects any &lt;input&gt; when focused */
+input:focus {
+ color: red;
+}</pre>
+
+<div class="note">
+<p><strong>提示:</strong>此伪类仅适用于焦点元素本身。如果要选择包含焦点元素的元素,请使用{{cssxref(":focus-within")}} 。</p>
+</div>
+
+<h2 id="语法">语法</h2>
+
+<pre>{{csssyntax}}</pre>
+
+<h2 id="Example">Example</h2>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;input class="red-input" value="I'll be red when focused."&gt;&lt;br&gt;
+&lt;input class="blue-input" value="I'll be blue when focused."&gt;</pre>
+
+<h3 id="CSS">CSS</h3>
+
+<pre class="brush: css">.red-input:focus {
+ background: yellow;
+ color: red;
+}
+
+.blue-input:focus {
+ background: yellow;
+ color: blue;
+}</pre>
+
+<h3 id="结果">结果</h3>
+
+<p>{{EmbedLiveSample('Example')}}</p>
+
+<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>{{SpecName('HTML WHATWG', 'scripting.html#selector-focus', ':focus')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td>Defines HTML-specific semantics.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS4 Selectors', '#focus-pseudo', ':focus')}}</td>
+ <td>{{Spec2('CSS4 Selectors')}}</td>
+ <td>No change.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS3 Selectors', '#the-user-action-pseudo-classes-hover-act', ':focus')}}</td>
+ <td>{{Spec2('CSS3 Selectors')}}</td>
+ <td>No change.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS2.1', 'selector.html#dynamic-pseudo-classes', ':focus')}}</td>
+ <td>{{Spec2('CSS2.1')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("css.selectors.focus")}}</p>
+
+<div id="compat-mobile"> </div>
+
+<h2 id="参考">参考</h2>
+
+<ul>
+ <li>{{cssxref(":focus-within")}}</li>
+</ul>