forked from mwmeyer/CSS-Positioning-101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.relative_pos.html
40 lines (36 loc) · 915 Bytes
/
2.relative_pos.html
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
<!DOCTYPE html>
<html>
<head>
<title>Relative Positioning</title>
<style>
/* Relative positioning follows the normal flow (elements stack on top of one another along the y-axis)
just like static positioning but unlike static, relative can be offset using properties like top, left, right, etc. */
#red_box {
position: static;
width: 200px;
height: 200px;
background: #ee3e64;
left: 200px; /* doesn't work */
}
#blue_box {
position: relative;
width: 200px;
height: 200px;
background: #44accf;
left: 200px; /* this moves box_2 because it is relativly positioned */
}
#green_box {
position: static;
width: 200px;
height: 200px;
background: #b7d84b;
left: 200px; /* doesn't work */
}
</style>
</head>
<body>
<div id="red_box" class="box">Static</div>
<div id="blue_box" class="box">Relative</div>
<div id="green_box" class="box">Static</div>
</body>
</html>