aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/css/_colon_focus/index.html
blob: a363d17db2c0c3dbd53ce55385445aedd8963ff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
title: ':focus'
slug: 'Web/CSS/:focus'
tags:
  - CSS
  - Layout
  - Reference
  - Web
  - ウェブ
  - セレクター
  - レイアウト
  - 擬似クラス
  - 疑似クラス
translation_of: 'Web/CSS/:focus'
---
<div>{{CSSRef}}</div>

<p><strong><code>:focus</code></strong><a href="/ja/docs/Web/CSS">CSS</a><a href="/ja/docs/Web/CSS/Pseudo-classes" title="Pseudo-classes">擬似クラス</a>で、フォーカスを持っている (フォームの入力のような) 要素を表します。普通はユーザーが要素をクリックやタップをしたり、キーボードの[タブ]キーで選択したりしたときです。</p>

<pre class="brush: css no-line-numbers notranslate">/* フォーカスを持つ &lt;input&gt; 要素を選択 */
input:focus {
  color: red;
}</pre>

<div class="blockIndicator note">
<p><strong>メモ:</strong> この擬似クラスはフォーカスを持つ要素に対してのみ適用されます。フォーカスを持つ要素を<em>含む</em>要素を選択したい場合は、 {{CSSxRef(":focus-within")}} を使用してください。</p>
</div>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox notranslate">{{CSSSyntax}}</pre>

<h2 id="Example" name="Example"></h2>

<h3 id="HTML">HTML</h3>

<pre class="brush: html no-line-numbers notranslate">&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 highlight[1, 6] notranslate">.red-input:focus {
  background: yellow;
  color: red;
}

.blue-input:focus {
  background: yellow;
  color: blue;
}</pre>

<h3 id="Result" name="Result">結果</h3>

<p>{{EmbedLiveSample("Example")}}</p>

<h2 id="Accessibility_Concerns" name="Accessibility_Concerns">アクセシビリティの考慮事項</h2>

<p>視覚的なフォーカスインジケーターが、弱視の人々からも見えるように確認してください。これは外光が明るい場所 (太陽の下の屋外など) で画面を使用するすべての人にも利益になります。 <a href="https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html">WCAG 2.1 SC 1.4.11 Non-Text Contrast</a> は、視覚的なフォーカスインジケーターを少なくとも 3:1 にすることを要求しています。</p>

<ul>
 <li>Accessible Visual Focus Indicators: <a href="https://www.deque.com/blog/give-site-focus-tips-designing-usable-focus-indicators/">Give Your Site Some Focus! Tips for Designing Useful and Usable Focus Indicators</a></li>
</ul>

<h3 id="focus_outline_none"><code>:focus { outline: none; }</code></h3>

<p><a href="https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html">WCAG 2.1 SC 1.4.11 Non-Text Contrast</a> を満たすフォーカスの輪郭線で置き換えることなく、フォーカスの輪郭線 (視覚的なフォーカスインジケーター) を単に削除しないでください。</p>

<ul>
 <li>Quick Tip:  <a href="https://a11yproject.com/posts/never-remove-css-outlines/">Never remove CSS outlines</a></li>
</ul>

<h2 id="Specifications" name="Specifications">仕様書</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-focus", ":focus")}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td>HTML に依存した意味論を定義。</td>
  </tr>
  <tr>
   <td>{{SpecName("CSS4 Selectors", "#focus-pseudo", ":focus")}}</td>
   <td>{{Spec2("CSS4 Selectors")}}</td>
   <td>変更なし。</td>
  </tr>
  <tr>
   <td>{{SpecName("CSS3 Selectors", "#the-user-action-pseudo-classes-hover-act", ":focus")}}</td>
   <td>{{Spec2("CSS3 Selectors")}}</td>
   <td>変更なし。</td>
  </tr>
  <tr>
   <td>{{SpecName("CSS2.1", "selector.html#dynamic-pseudo-classes", ":focus")}}</td>
   <td>{{Spec2("CSS2.1")}}</td>
   <td>初回定義。</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>

<div>
<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>

<p>{{Compat("css.selectors.focus")}}</p>
</div>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li>{{CSSxRef(":focus-visible")}} {{Experimental_Inline}}</li>
 <li>{{CSSxRef(":focus-within")}}</li>
</ul>