aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/css/_colon_dir/index.html
blob: 5a97d10b89b9824837840550e4eab3e63820dadb (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
---
title: ':dir()'
slug: 'Web/CSS/:dir'
tags:
  - BiDi
  - CSS
  - Experimental
  - Pseudo-class
  - Reference
  - セレクター
  - 疑似クラス
translation_of: 'Web/CSS/:dir'
---
<div>{{CSSRef}}</div>

<p><strong><code>:dir()</code><a href="/ja/docs/Web/CSS">CSS</a></strong> <a href="/ja/docs/CSS/Web/Pseudo-classes">擬似クラス</a>で、中に含まれる文字列の方向に基づいて要素を選択します。</p>

<pre class="brush: css no-line-numbers notranslate">/* 右から左への文字列がある要素すべてを選択 */
:dir(rtl) {
  background-color: red;
}</pre>

<p><code>:dir()</code> 擬似クラスは文字方向の意味的な値、つまり、文書自身に設定されているもののみを使用します。スタイルによる文字方向、つまり、 {{cssxref("direction")}} のような CSS プロパティで設定された文字方向には対応しません。</p>

<div class="note">
<p><strong>メモ:</strong> <code>:dir()</code> 擬似クラスは <code>[dir=…]</code> <a href="/ja/docs/Web/CSS/Attribute_selectors">属性セレクター</a> とは等価でないことに注意してください。後者は HTML の {{htmlattrxref("dir")}} 属性を選択しますが、これがない要素は、文字方向が親から継承されていても無視します。(同様に、 <code>[dir=rtl]</code><code>[dir=ltr]</code><code>auto</code> の値を選択しません。)それに対して、 <code>:dir()</code> は継承の場合も含め、{{glossary("user agent", "ユーザーエージェント")}} が計算した値で選択します。</p>
</div>

<div class="note">
<p><strong>メモ:</strong> HTML では、文字方向は {{htmlattrxref("dir")}} 属性で指定されます。他の文書タイプでは異なる方法があるかもしれません。</p>
</div>

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

<p><code>:dir()</code> 擬似クラスは1つの引数を取り、対象としたい文字方向を指定します。</p>

<h3 id="Parameters" name="Parameters">引数</h3>

<dl>
 <dt><code>ltr</code></dt>
 <dd>文字方向が左から右の要素を対象とします。</dd>
 <dt><code>rtl</code></dt>
 <dd>文字方向が右から左の要素を対象とします。</dd>
</dl>

<h3 id="Formal_syntax" name="Formal_syntax">形式文法</h3>

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

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

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

<pre class="brush:html; notranslate">&lt;div dir="rtl"&gt;
  &lt;span&gt;test1&lt;/span&gt;
  &lt;div dir="ltr"&gt;test2
    &lt;div dir="auto"&gt;עִבְרִית&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css notranslate">:dir(ltr) {
  background-color: yellow;
}

:dir(rtl) {
  background-color: powderblue;
}</pre>

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

<p>{{ EmbedLiveSample('Examples') }}</p>

<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-ltr', ':dir(ltr)')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>変更なし。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS4 Selectors', '#the-dir-pseudo', ':dir()')}}</td>
   <td>{{Spec2('CSS4 Selectors')}}</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.dir")}}</p>
</div>

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

<ul>
 <li>言語に関連する擬似クラス: {{cssxref(":lang")}}, {{cssxref(":dir")}}</li>
</ul>