aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/css/margin-left/index.html
blob: ecbf6a60479d7463cc2aca8f33d4558b6a63302b (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
---
title: margin-left
slug: Web/CSS/margin-left
tags:
  - CSS
  - CSS Property
  - Layout
  - Reference
  - 'recipe:css-property'
translation_of: Web/CSS/margin-left
---
<div>{{CSSRef}}</div>

<p><strong><code>margin-left</code></strong><a href="/ja/docs/Web/CSS">CSS</a> のプロパティで、要素の左側の<a href="/ja/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model">マージン領域</a>を設定します。正の数を指定すると、隣との間が遠くなるように配置され、負の数を指定すると、近くなるように配置します。</p>

<div>{{EmbedInteractiveExample("pages/css/margin-left.html")}}</div>

<div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div>

<p>二つの隣り合うボックスの垂直マージンは融合することがあります。これは<a href="/ja/docs/CSS/margin_collapsing"><em>マージンの相殺</em></a>と呼ばれています。</p>

<p>まれに幅の制約がきつすぎると (つまり、 <code>width</code>, <code>margin-left</code>, <code>border</code>, <code>padding</code>, コンテンツ領域, <code>margin-right</code> がすべて定義されていた場合)、 <code>margin-left</code> は無視され、 <code>auto</code> が設定されていたときと同じ計算値になります。</p>

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

<pre class="brush:css no-line-numbers notranslate">/* &lt;length&gt; 値 */
margin-left: 10px;  /* 絶対的な寸法 */
margin-left: 1em;   /* 文字の寸法からの相対 */
margin-left: 5%;    /* 直近のブロックコンテナーの幅からの相対 */

/* キーワード値 */
margin-left: auto;

/* グローバル値 */
margin-left: inherit;
margin-left: initial;
margin-left: unset;
</pre>

<p><code>margin-left</code> プロパティは <code>auto</code> キーワード、または <code>&lt;length&gt;</code><code>&lt;percentage&gt;</code> で指定されます。正の数、ゼロ、負の数が指定できます。</p>

<h3 id="Values" name="Values"></h3>

<dl>
 <dt>{{cssxref("&lt;length&gt;")}}</dt>
 <dd>固定値によるマージンの寸法です。</dd>
 <dt>{{cssxref("&lt;percentage&gt;")}}</dt>
 <dd>包含ブロックの <em>width</em> に対するパーセントによるマージンの寸法です。</dd>
 <dt><code>auto</code></dt>
 <dd>左マージンは未使用の水平方向の余白を共有します。これは主に使用されているレイアウトモードによって決定されます。 <code>margin-left</code><code>margin-right</code> の両方が <code>auto</code> の場合は、両方に均等に割り当てられます。それ以外の場合は以下の表のとおりです。
 <table class="standard-table">
  <thead>
   <tr>
    <th scope="col">{{cssxref("display")}} の値</th>
    <th scope="col">{{cssxref("float")}} の値</th>
    <th scope="col">{{cssxref("position")}} の値</th>
    <th scope="col"><code>auto</code> の計算値</th>
    <th scope="col">コメント</th>
   </tr>
  </thead>
  <tbody>
   <tr>
    <th><code>inline</code>, <code>inline-block</code>, <code>inline-table</code></th>
    <th><em>任意</em></th>
    <th><code>static</code> または <code>relative</code></th>
    <td><code>0</code></td>
    <td>インラインレイアウトモード</td>
   </tr>
   <tr>
    <th><code>block</code>, <code>inline</code>, <code>inline-block</code>, <code>block</code>, <code>table</code>, <code>inline-table</code>, <code>list-item</code>, <code>table-caption</code></th>
    <th><em>任意</em></th>
    <th><code>static</code> または <code>relative</code></th>
    <td><code>0</code>。ただし <code>margin-left</code><code>margin-right</code> が共に <code>auto</code> に設定されていた場合は、親要素の中で中央揃えする値に設定されます。</td>
    <td>ブロックレイアウトモード</td>
   </tr>
   <tr>
    <th><code>block</code>, <code>inline</code>, <code>inline-block</code>, <code>block</code>, <code>table</code>, <code>inline-table</code>, <code>list-item</code>, <code>table-caption</code></th>
    <th><code>left</code> または <code>right</code></th>
    <th><code>static</code> または <code>relative</code></th>
    <td><code>0</code></td>
    <td>ブロックレイアウトモード (フロート要素)</td>
   </tr>
   <tr>
    <th><code>table-*</code> <em>すべて</em>、ただし <code>table-caption</code> <em>を除く</em></th>
    <th><em>任意</em></th>
    <th><em>任意</em></th>
    <td><code>0</code></td>
    <td>内部の <code>table-*</code> 要素にはマージンがありません。代わりに {{ cssxref("border-spacing") }} を使用してください</td>
   </tr>
   <tr>
    <th><code>flex</code><code>inline-flex</code>, <code>table-*</code> <em>以外のすべて</em></th>
    <th><em>任意</em></th>
    <th><em><code>fixed</code></em> または <code>absolute</code></th>
    <td><code>0</code>。ただし <code>margin-left</code><code>margin-right</code> が共に <code>auto</code> に設定されていた場合は、ボーダー領域を <code>width</code> の中で中央揃えする値に設定されます(固定されている場合)。</td>
    <td>絶対位置指定配置モード</td>
   </tr>
   <tr>
    <th><code>flex</code>, <code>inline-flex</code></th>
    <th><em>任意</em></th>
    <th><em>任意</em></th>
    <td><code>0</code>。ただし、水平に正の余白がある場合は、 <code>auto</code> を指定したすべてのマージンに均等に割り振られます。</td>
    <td>フレックスボックス配置モード</td>
   </tr>
  </tbody>
 </table>
 </dd>
</dl>

<h2 id="Formal_definition" name="Formal_definition">公式定義</h2>

<p>{{cssinfo}}</p>

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

{{csssyntax}}

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

<h3 id="Setting_left_margin_using_pixels_and_percentages" name="Setting_left_margin_using_pixels_and_percentages">ピクセル数とパーセント値を使用した左マージンの設定</h3>

<pre class="brush: css notranslate">.content { margin-left: 5%; }
.sidebox { margin-left: 10px; }
.logo    { margin-left: -5px; }
</pre>

<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('CSS3 Box', '#propdef-margin-left', 'margin-left')}}</td>
   <td>{{Spec2('CSS3 Box')}}</td>
   <td>CSS 2.1 から目立った変更なし。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Flexbox', '#item-margins', 'margin-left')}}</td>
   <td>{{Spec2('CSS3 Flexbox')}}</td>
   <td>フレックス項目での <code>margin-left</code> の挙動を定義。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'box.html#margin-properties', 'margin-left')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>CSS1 と同様、ただしインライン要素での効果は削除。</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#margin-left', 'margin-left')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>初回定義</td>
  </tr>
 </tbody>
</table>

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

<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.properties.margin-left")}}</p>

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

<ul>
 <li>{{cssxref("margin-top")}}, {{cssxref("margin-right")}}, {{cssxref("margin-bottom")}}{{cssxref("margin")}} 一括指定</li>
 <li>対応付けられる論理的プロパティ: {{cssxref("margin-block-start")}}, {{cssxref("margin-block-end")}}, {{cssxref("margin-inline-start")}}, {{cssxref("margin-inline-end")}} および一括指定の {{cssxref("margin-block")}}{{cssxref("margin-inline")}}</li>
</ul>