I have wanted to make a button that is aligned horizontally underneath the text that says “Bubbles”. I have tried flex already and in the snippet I try it with transform but regardless of what I try I wont get the desired outcome. So please Help!
JavaScript
x
24
24
1
section {
2
width: 100%;
3
height: 100vh;
4
overflow: hidden;
5
background: #1F69FA;
6
display: flex;
7
justify-content: center;
8
align-items: center;
9
}
10
11
section container {
12
height: 200px;
13
position: relative;
14
border: 3px solid green;
15
}
16
17
section center {
18
margin: 0;
19
position: absolute;
20
top: 50%;
21
left: 50%;
22
-ms-transform: translate(-50%, -50%);
23
transform: translate(-50%, -50%);
24
}
JavaScript
1
7
1
<section>
2
<div class="container">
3
<div class="container">
4
<button type="button" onclick="next()"> Next </button>
5
</div>
6
</div>
7
</section>
Advertisement
Answer
Since you’ve got the container class but aren’t actually using it, we can just make it a flex column and put both elements inside of it
JavaScript
1
15
15
1
function Seifenblasen_blasen() {
2
const section = document.querySelector('section')
3
const createElement = document.createElement('spawn')
4
var size = Math.random() * 60;
5
createElement.style.width = 30 + size + 'px';
6
createElement.style.height = 30 + size + 'px';
7
createElement.style.left = Math.random() * innerWidth + "px";
8
section.appendChild(createElement);
9
10
setTimeout(() => {
11
createElement.remove()
12
}, 8000)
13
14
}
15
const Blaseninterval = setInterval(Seifenblasen_blasen, 100)
JavaScript
1
86
86
1
{
2
margin: 0;
3
padding: 0;
4
}
5
6
.container {
7
display: flex;
8
flex-direction: column;
9
justify-content: center;
10
align-items: center;
11
}
12
13
section {
14
width: 100%;
15
height: 100vh;
16
overflow: hidden;
17
background: #1F69FA;
18
display: flex;
19
justify-content: center;
20
align-items: center;
21
}
22
23
section h2 {
24
font-size: 10em;
25
color: #333;
26
margin: 0 auto;
27
text-align: center;
28
font-family: consolas;
29
}
30
31
section spawn {
32
position: absolute;
33
bottom: -80px;
34
background: transparent;
35
border-radius: 50%;
36
pointer-events: none;
37
box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5);
38
animation: animate 4s linear infinite;
39
}
40
41
section spawn:before {
42
content: '';
43
position: absolute;
44
width: 100%;
45
height: 100%;
46
transform: scale(0.25) translate(-70%, -70%);
47
background: radial-gradient(#fff, transparent);
48
opacity: 0.6;
49
border-radius: 50%;
50
}
51
52
@keyframes animate {
53
0% {
54
transform: translateY(0%);
55
opacity: 1;
56
}
57
99% {
58
opacity: 1;
59
}
60
100% {
61
transform: translateY(-2000%);
62
opacity: 0;
63
}
64
section span {
65
margin-top: 700px;
66
font-size: 1em;
67
color: #333;
68
margin: 0 auto;
69
font-family: consolas;
70
background-color: #1F69FA;
71
border: none;
72
position: absolute;
73
}
74
section container {
75
height: 200px;
76
position: relative;
77
border: 3px solid green;
78
}
79
section center {
80
margin: 0;
81
position: absolute;
82
top: 50%;
83
left: 50%;
84
-ms-transform: translate(-50%, -50%);
85
transform: translate(-50%, -50%);
86
}
JavaScript
1
6
1
<section>
2
<div class="container">
3
<h2> Bubbles </h2>
4
<button type="button" onclick="next()"> Next </button>
5
</div>
6
</section>