--- title: left slug: Web/CSS/left tags: - CSS - CSS Property - CSS プロパティ - CSS 位置指定レイアウト - Reference translation_of: Web/CSS/left ---
left は CSS のプロパティで、位置指定要素の水平位置の決定に関与します。位置指定されていない要素には効果はありません。
left の効果は、要素がどの様に配置されているか (つまり、 {{cssxref("position")}} プロパティの値) によって変わります。
position が absolute 又は fixed に設定されている場合、 left プロパティは要素の左辺と包含ブロックの左辺との間の距離を指定します。 (包含ブロックは相対配置された祖先の要素です。)position が relative に設定されている場合、 left プロパティは要素の左辺が通常位置から右方向へ移動する量を指定します。position が sticky に設定されている場合、 left プロパティは sticky 制約の矩形を計算するために使用されます。position が static に設定されている場合、 left プロパティは効果がありません。left と {{cssxref("right")}} の両方が定義されていて、幅の制約がない場合、要素は両方を満たすように伸縮されます。要素が両方を満たすように伸縮できない場合、要素の位置は過剰指定になります。このような場合、包含ブロックが左書きの場合は left の値が優先され、包含ブロックが右書きの場合は right の値が優先されます。
/* <length> 値 */ left: 3px; left: 2.4em; /* 内包ブロックの幅に対する <percentage> */ left: 10%; /* キーワード値 */ left: auto; /* グローバル値 */ left: inherit; left: initial; left: unset;
autowidth: auto は内容物の幅に基づいて決まります。また、 right も auto であった場合は、要素は水平方向には静的要素が配置される場合と同様に配置されます。right も auto であった場合は、水平方向には移動しません。inheritauto キーワードと同様に扱われます。#wrap {
width: 700px;
margin: 0 auto;
background: #5C5C5C;
}
pre {
white-space: pre;
white-space: pre-wrap;
white-space: pre-line;
word-wrap: break-word;
}
#example_1 {
width: 200px;
height: 200px;
position: absolute;
left: 20px;
top: 20px;
background-color: #D8F5FF;
}
#example_2 {
width: 200px;
height: 200px;
position: relative;
top: 0;
right: 0;
background-color: #C1FFDB;
}
#example_3 {
width: 600px;
height: 400px;
position: relative;
top: 20px;
left: 20px;
background-color: #FFD7C2;
}
#example_4 {
width:200px;
height:200px;
position:absolute;
bottom:10px;
right:20px;
background-color:#FFC7E4;
}
#example_5 {
position: absolute;
right: 0;
left: 0;
top: 100px;
background-color: #D7FFC2;
}
<div id="wrap">
<div id="example_1">
<pre>
position: absolute;
left: 20px;
top: 20px;
</pre>
<p>The only containing element for this div is the main window, so it positions itself in relation to it.</p>
</div>
<div id="example_2">
<pre>
position: relative;
top: 0;
right: 0;
</pre>
<p>Relative position in relation to its siblings.</p>
</div>
<div id="example_3">
<pre>
float: right;
position: relative;
top: 20px;
left: 20px;
</pre>
<p>Relative to its sibling div above, but removed from flow of content.</p>
<div id="example_4">
<pre>
position: absolute;
bottom: 10px;
right: 20px;
</pre>
<p>Absolute position inside of a parent with relative position</p>
</div>
<div id="example_5">
<pre>
position: absolute;
right: 0;
left: 0;
top: 200px;
</pre>
<p>Absolute position with both left and right declared</p> </div>
</div>
</div>
{{EmbedLiveSample('Examples',1200,650)}}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('CSS3 Positioning', '#propdef-left', 'left')}} | {{Spec2('CSS3 Positioning')}} | sticky の位置の動作を追加 |
| {{SpecName('CSS2.1', 'visuren.html#propdef-left', 'left')}} | {{Spec2('CSS2.1')}} | 初回定義 |
{{cssinfo}}
{{Compat("css.properties.left")}}