-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelative.html
180 lines (157 loc) · 5.38 KB
/
relative.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Position | Relative</title>
<style>
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body{
font-family: Arial, Helvetica, sans-serif;
height: 100%;
}
.container {
margin: auto;
max-width: 900px;
padding: 1rem;
}
a, a:visited {
text-decoration: none;
}
a.current-link {
background-color: navy;
}
header.hero {
background-color: royalblue;
position: sticky;
top: 0;
right: 0;
box-shadow: 0px 0px 10px #000;
font-size: 1.2rem;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
text-transform: uppercase;
}
.hero .container {
display: flex;
justify-content: space-between;
align-items: center;
}
.hero h1 {
font-size: 1.2rem;
letter-spacing: 0.3rem;
padding: 0.5rem;
}
.hero ul {
list-style: none;
}
.hero ul li {
display: inline-block;
margin-right: 1rem;
}
.hero ul li a {
color: #fff;
padding: 0.5rem 0.75rem;
border-radius: 0.5rem;
}
.main > p{
margin: 1rem 0 0 0;
text-align: center;
font-size: 1.1rem;
}
.section {
padding: 1rem;
margin: 2rem auto;
max-width: 400px;
background-color: lightskyblue;
/* text-align: center; */
color: white;
max-width: 100%;
}
.section h2 {
font-size: 1.3rem;
background-color: darkgreen;
padding: 1rem;
}
.section p {
font-size: 1.1rem;
background-color: darkgreen;
padding: 1rem;
}
.section .box {
background-color: navy;
width: 200px;
height: 200px;
margin: 2rem 0;
}
section.position-relative .relative {
position: relative;
left: 50%;
top: 5em;
}
@media screen and (max-width: 800px) {
.hero .container {
flex-direction: column;
justify-content: center;
}
.hero h1 {
margin-bottom: 1rem;
}
}
@media screen and (max-width: 600px) {
.hero h1 {
margin-bottom: 0;
}
.hero ul {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.hero ul li {
padding: 0.25 0;
margin: 1.5rem 0 0 0;
font-size: 1rem;
}
}
</style>
</head>
<body>
<header class="hero">
<div class="container">
<h1>CSS Position</h1>
<ul class="navbar">
<li><a href="./index.html">static</a></li>
<li><a href="./relative.html" class="current-link">relative</a></li>
<li><a href="./absolute.html">absolute</a></li>
<li><a href="./fixed.html">fixed</a></li>
<li><a href="./sticky.html">sticky</a></li>
</ul>
</div>
</header>
<main class="main container">
<section class="section position-relative">
<h2><code>position: relative;</code></h2>
<div class="relative box"></div>
<p>The above box has <strong><code>position: relative;</code></strong></p>
</section>
<p>Note how the <code>div.relative</code> element appears in the normal flow of document.</p>
<p>Then the element is placed <em>relative to itself</em> depending on the values of <code>top, right, left, bottom</code>.</p>
<p>In the above example, the box is placed <br/>
<strong style="display: inline-block; margin-top: 0.1rem; padding: 0.5rem 1rem; background-color:yellowgreen;">
<code>
div.relative {
position: relative;
left: 50%;
top: 5em;
}
</code>
</strong>
</p>
</main>
</body>
</html>