-
Notifications
You must be signed in to change notification settings - Fork 0
/
11_position.html
151 lines (146 loc) · 4.08 KB
/
11_position.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Positioning</title>
</head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
height: 2000px;
max-width: 1100px;
}
.container {
width: 450px;
height: 450px;
position: relative;
background: gainsboro;
text-align: center;
}
.box {
height: 100px;
width: 100px;
}
#box-1 {
position: relative;
/* float: right; */
top: 400px;
left: 600px;
background: yellowgreen;
}
#box-2 {
position: absolute;
top: 100px;
left: 100px;
background: yellow;
}
#box-3 {
position: absolute;
bottom: 100px;
right: 100px;
background: blue;
}
#box-x {
position: absolute;
bottom: 200px;
right: 100px;
background: black;
}
#box-y {
position: absolute;
bottom: 100px;
right: 100px;
background: red;
}
#box-4 {
position: fixed;
background: red;
}
#box-5 {
/* top position must be set to fix the point where the box is fixed */
top: 0px;
position: sticky;
position: -webkit-sticky;
background: orange;
}
.normal {
background: steelblue;
}
</style>
<body>
<div id="box-1" class="box">
I'm a Relative display box
</div>
<!-- <div class="box normal">
I'm a normal element
</div> -->
<div class="container">
<div id="box-2" class="box"></div>
<div id="box-3" class="box">
<div id="box-x" class="box">
<div id="box-y" class="box"></div>
</div>
</div>
</div>
<div id="box-4" class="box">
I'm a fixed box
</div>
<div id="box-5" class="box">
I'm a sticky box
</div>
<br/>
<br/>
<br/>
<table>
<tbody>
<tr>
<th style="width:14%">Value</th>
<th>Description</th>
</tr>
<tr>
<td>static</td>
<td>Default value. Elements render in order, as they appear in
the document flow</td>
</tr>
<tr>
<td>absolute</td>
<td>The element is positioned relative to its first positioned
(not static) ancestor element</td>
</tr>
<tr>
<td>fixed</td>
<td>The element is positioned relative to the browser window</td>
</tr>
<tr>
<td>relative</td>
<td>The element is positioned relative to its normal position,
so "left:20px"
adds 20 pixels to the element's LEFT position</td>
</tr>
<tr>
<td>sticky</td>
<td>The element is positioned based on the user's scroll
position
<p>A sticky element toggles between <code class="w3-codespan">relative</code>
and <code class="w3-codespan">fixed</code>, depending on the
scroll position. It is positioned relative until a given
offset position is met in the viewport - then it "sticks" in
place (like position:fixed).</p>
<strong>Note:</strong> Not supported in IE/Edge 15 or earlier.
Supported in Safari from version 6.1 with a -webkit- prefix.</td>
</tr>
<tr>
<td>initial</td>
<td>Sets this property to its default value. <a
href="css_initial.asp">Read about <em>initial</em></a></td>
</tr>
<tr>
<td>inherit</td>
<td>Inherits this property from its parent element. <a
href="css_inherit.asp">Read about <em>inherit</em></a></td>
</tr>
</tbody>
</table>
</body>
</html>