-
Notifications
You must be signed in to change notification settings - Fork 0
/
4. Display_and_Position.html
189 lines (164 loc) · 5.34 KB
/
4. Display_and_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
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
181
182
183
184
185
186
187
188
189
<!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" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;400;700&display=swap"
rel="stylesheet"
/>
<title>Display & Position</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: "Inter", sans-serif;
}
/* Display Section starts here */
h1 {
text-align: center;
}
header {
margin: auto;
display: block;
border: 2px solid burlywood;
width: 100%;
}
img {
margin: auto;
width: 200px;
display: block;
padding: 10px;
}
h3 {
margin: 0px;
text-align: center;
}
.container {
display: inline-block;
width: 100%;
/* border: 2px solid steelblue; */
}
.box {
margin-top: 20px;
padding: 10px;
display: inline-block;
width: 33%;
border: 2px solid steelblue;
text-align: justify;
}
/* Display section ends here */
/* Position Section starts here */
.container2 {
border: 2px solid red;
margin-top: 50px;
height: 400px;
background-color: rgb(218, 218, 218);
}
.box2 {
margin: 10px;
border: 2px solid green;
display: inline-block;
width: 200px;
height: 100px;
}
/* CSS Position: static (default), relative, absolute, fixed, sticky */
/* position: static;
It is the default position of HTML elements. */
/* relative: Positions the element relative to its normal positon and will leave a gap at its normal position.
We can set the top, right, bottom, and left properties that will cause the element to adjust away from the normal position.*/
/* absolute: Positions the element relative to the positon of its first parent.
In the absence of any parent element, the HTML element will be placed relative to the page.*/
/* fixed: Positions the element relative to the browser window;
An element with position:fixed; will remain stuck to a specific position even after the page is scrolled.*/
/* sticky: Positions the element relative to the users scroll position:
It is a hybrid of relative and fixed position.
An HTML element with position:sticky; will just sit there until a given position offset is met. */
#displaybox1 {
position: static;
/* Default position is static for all elements */
}
#displaybox2 {
position: relative;
top: 20px;
left: 20px;
}
#displaybox3 {
position: absolute;
bottom: 20px;
left: 500px;
}
#displaybox4 {
position: fixed;
top: 300px;
right: 20px;
}
#displaybox5 {
position: sticky;
top: 300px;
right: 100px;
}
#displaybox6 {
position: static;
}
/* Position Section ends here */
</style>
</head>
<body>
<!-- /* Display Section starts here */ -->
<h1>Display & Position</h1>
<hr />
<header class="top">
<img
src="https://source.unsplash.com/collection/190727/1600x900"
alt="random unsplash image"
/>
<h3>Display</h3>
</header>
<div class="container">
<div class="box">
<h4>Heading1</h4>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odio ea
perferendis rerum, qui optio provident. Reprehenderit provident
quaerat voluptate laborum consequuntur tempore mollitia maiores rem.
Quisquam dicta, magnam incidunt odit, hic necessitatibus, quidem vel
illo enim et minus dolorem recusandae!
</p>
</div>
<div class="box">
<h4>Heading2</h4>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odio ea
perferendis rerum, qui optio provident. Reprehenderit provident
quaerat voluptate laborum consequuntur tempore mollitia maiores rem.
Quisquam dicta, magnam incidunt odit, hic necessitatibus, quidem vel
illo enim et minus dolorem recusandae!
</p>
</div>
<div class="box">
<h4>Heading3</h4>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odio ea
perferendis rerum, qui optio provident. Reprehenderit provident
quaerat voluptate laborum consequuntur tempore mollitia maiores rem.
Quisquam dicta, magnam incidunt odit, hic necessitatibus, quidem vel
illo enim et minus dolorem recusandae!
</p>
</div>
</div>
<!-- /* Display Section Ends here */ -->
<!-- /* Position Section starts here */ -->
<div class="container2">
<div class="box2" id="displaybox1">1. Static</div>
<div class="box2" id="displaybox2">2. Relative</div>
<div class="box2" id="displaybox3">3. Absolute</div>
<div class="box2" id="displaybox4">4. Fixed</div>
<div class="box2" id="displaybox5">5. Sticky</div>
<div class="box2" id="displaybox6">6. Static</div>
</div>
</body>
</html>