The left CSS property specifies part of the position of positioned elements.
For absolutely positioned elements (those with position: absolute or position: fixed), it specifies the distance between the left margin edge of the element and the left edge of its containing block.
Initialauto
Applies topositioned elements
Inheritedno
Percentagesrefer to the width of the containing block
Mediavisual
Computed Valueif specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto
Animatableyes, as a length, percentage or calc(); when both values are lengths, they are interpolated as lengths; when both values are percentages, they are interpolated as percentages; otherwise, both values are converted into a calc() function that is the sum of a length and a percentage (each possibly zero), and these calc() functions have each half interpolated as real numbers.
Canonical orderthe unique non-ambiguous order defined by the formal grammar
Syntax
Formal syntax: <length> | <percentage> | auto
left: 3px /* <length> values */
left: 2.4em
left: 10% /* <percentages> of the width of the containing block */
left: auto
left: inherit
Values
<length>
Is a negative, null, or positive <length> that represents:
for absolutely positioned elements, the distance to the left edge of the containing block
for relatively positioned elements, the offset that the element is moved left from its position in the normal flow if it wasn’t positioned.
<percentage>
Is a <percentage> of the containing block’s width, used as described in the summary.
auto
Is a keyword that represents:
for absolutely positioned elements, the position of the element based on the right property and treat width: auto as a width based on the content.
for relatively positioned elements, the left offset of the element from its original position based on the right property, or if right is also auto, do not offset it at all.
inherit
Is a keyword indicating that the value is the same as the computed value from its parent element (which may not be its containing block). This computed value is then handled like it was a <length>, <percentage> or the auto keyword.
Examples
01
#wrap {
02
width: 700px;
03
margin: 0auto;
04
background: #5C5C5C;
05
}
06
pre{
07
white-space: pre;
08
white-space: pre-wrap;
09
white-space: pre-line;
10
word-wrap: break-word;
11
}
12
#example_1{
13
width: 200px;
14
height: 200px;
15
position: absolute;
16
left: 20px;
17
top: 20px;
18
background-color: #D8F5FF;
19
}
20
#example_2{
21
width: 200px;
22
height: 200px;
23
position: relative;
24
top: 0;
25
right: 0;
26
background-color: #C1FFDB;
27
}
28
#example_3{
29
width: 600px;
30
height: 400px;
31
position: relative;
32
top: 20px;
33
left: 20px;
34
background-color: #FFD7C2;
35
}
36
#example_4{
37
width:200px;
38
height:200px;
39
position:absolute;
40
bottom:10px;
41
right:20px;
42
background-color:#FFC7E4;
43
}
01
<divid="wrap">
02
<divid="example_1">
03
<pre>
04
position: absolute;
05
left: 20px;
06
top: 20px;
07
</pre>
08
<p>The only containing element for this div is the main window, so it positions itself in relation to it.</p>
09
</div>
10
<divid="example_2">
11
<pre>
12
position: relative;
13
top: 0;
14
right: 0;
15
</pre>
16
<p>Relative position in relation to its siblings.</p>
17
</div>
18
<divid="example_3">
19
<pre>
20
float: right;
21
position: relative;
22
top: 20px;
23
left: 20px;
24
</pre>
25
<p>Relative to its sibling div above, but removed from flow of content.</p>
26
<divid="example_4">
27
<pre>
28
position: absolute;
29
top: 10px;
30
left: 20px;
31
</pre>
32
<p>Absolute position inside of a parent with relative position</p>