-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSS-stack-elements.html
99 lines (96 loc) · 2.05 KB
/
CSS-stack-elements.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stack Elements via CSS</title>
<style>
div {
text-align: center;
border-radius: 10px;
}
.parent {
width: 80vw;
height: 200px;
background: rgba(90, 153, 206, 0.486);
margin: 8vw 10vw;
border: 5px dashed rosybrown;
position: relative;
}
.child {
height: 150px;
width: 300px;
border: 3px dashed rgb(235, 7, 7);
background: slateblue;
position: absolute;
top: 0;
opacity: 0.7;
}
.ch1 {
left: 0;
}
.ch2 {
left: 150px;
}
code {
padding: 15px 0px;
}
h1 {
text-align: center;
color: rgb(5, 80, 42);
}
.outer {
position: relative;
left: 0;
right: 0;
margin: 0 auto;
/*^^^to position outer div on center*/
margin-top: 20px;
width: 500px;
height: 300px;
background-color: rgb(43, 226, 141);
}
.top {
position: absolute;
background: blueviolet;
width: 50px;
height: 20px;
/* opacity: 0.8; */
}
.bot {
position: absolute;
background: rgb(226, 141, 43);
width: 50px;
height: 20px;
top: 5%;
}
</style>
</head>
<body>
<h1>Method 1: Using the Position Property</h1>
<div class="parent">
<code>
PARENT <br />
position:relative;
</code>
<div class="child ch1">
<code
>position:absolute <br />
top:0 <br />
left:0</code
>
</div>
<div class="child ch2">
<code
>position:absolute <br />
top:0 <br />
left:150px</code
>
</div>
</div>
<div class="outer">
<div class="bot">Bottom</div>
<div class="top">Top</div>
</div>
</body>
</html>