无法使用 CSS 移动按钮
Can't move button with CSS
我想制作一个水平对齐的按钮,该按钮位于“Bubbles”文本下方。我已经尝试过 flex 并且在代码片段中我尝试了 transform 但无论我尝试什么我都不会得到想要的结果。所以请帮忙!
section {
width: 100%;
height: 100vh;
overflow: hidden;
background: #1F69FA;
display: flex;
justify-content: center;
align-items: center;
}
section container {
height: 200px;
position: relative;
border: 3px solid green;
}
section center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<section>
<div class="container">
<div class="container">
<button type="button" onclick="next()"> Next </button>
</div>
</div>
</section>
既然你已经有了容器class但实际上并没有使用它,我们可以把它做成一个弹性列并将两个元素都放在里面
function Seifenblasen_blasen() {
const section = document.querySelector('section')
const createElement = document.createElement('spawn')
var size = Math.random() * 60;
createElement.style.width = 30 + size + 'px';
createElement.style.height = 30 + size + 'px';
createElement.style.left = Math.random() * innerWidth + "px";
section.appendChild(createElement);
setTimeout(() => {
createElement.remove()
}, 8000)
}
const Blaseninterval = setInterval(Seifenblasen_blasen, 100)
{
margin: 0;
padding: 0;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
section {
width: 100%;
height: 100vh;
overflow: hidden;
background: #1F69FA;
display: flex;
justify-content: center;
align-items: center;
}
section h2 {
font-size: 10em;
color: #333;
margin: 0 auto;
text-align: center;
font-family: consolas;
}
section spawn {
position: absolute;
bottom: -80px;
background: transparent;
border-radius: 50%;
pointer-events: none;
box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5);
animation: animate 4s linear infinite;
}
section spawn:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
transform: scale(0.25) translate(-70%, -70%);
background: radial-gradient(#fff, transparent);
opacity: 0.6;
border-radius: 50%;
}
@keyframes animate {
0% {
transform: translateY(0%);
opacity: 1;
}
99% {
opacity: 1;
}
100% {
transform: translateY(-2000%);
opacity: 0;
}
section span {
margin-top: 700px;
font-size: 1em;
color: #333;
margin: 0 auto;
font-family: consolas;
background-color: #1F69FA;
border: none;
position: absolute;
}
section container {
height: 200px;
position: relative;
border: 3px solid green;
}
section center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<section>
<div class="container">
<h2> Bubbles </h2>
<button type="button" onclick="next()"> Next </button>
</div>
</section>
我想制作一个水平对齐的按钮,该按钮位于“Bubbles”文本下方。我已经尝试过 flex 并且在代码片段中我尝试了 transform 但无论我尝试什么我都不会得到想要的结果。所以请帮忙!
section {
width: 100%;
height: 100vh;
overflow: hidden;
background: #1F69FA;
display: flex;
justify-content: center;
align-items: center;
}
section container {
height: 200px;
position: relative;
border: 3px solid green;
}
section center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<section>
<div class="container">
<div class="container">
<button type="button" onclick="next()"> Next </button>
</div>
</div>
</section>
既然你已经有了容器class但实际上并没有使用它,我们可以把它做成一个弹性列并将两个元素都放在里面
function Seifenblasen_blasen() {
const section = document.querySelector('section')
const createElement = document.createElement('spawn')
var size = Math.random() * 60;
createElement.style.width = 30 + size + 'px';
createElement.style.height = 30 + size + 'px';
createElement.style.left = Math.random() * innerWidth + "px";
section.appendChild(createElement);
setTimeout(() => {
createElement.remove()
}, 8000)
}
const Blaseninterval = setInterval(Seifenblasen_blasen, 100)
{
margin: 0;
padding: 0;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
section {
width: 100%;
height: 100vh;
overflow: hidden;
background: #1F69FA;
display: flex;
justify-content: center;
align-items: center;
}
section h2 {
font-size: 10em;
color: #333;
margin: 0 auto;
text-align: center;
font-family: consolas;
}
section spawn {
position: absolute;
bottom: -80px;
background: transparent;
border-radius: 50%;
pointer-events: none;
box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5);
animation: animate 4s linear infinite;
}
section spawn:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
transform: scale(0.25) translate(-70%, -70%);
background: radial-gradient(#fff, transparent);
opacity: 0.6;
border-radius: 50%;
}
@keyframes animate {
0% {
transform: translateY(0%);
opacity: 1;
}
99% {
opacity: 1;
}
100% {
transform: translateY(-2000%);
opacity: 0;
}
section span {
margin-top: 700px;
font-size: 1em;
color: #333;
margin: 0 auto;
font-family: consolas;
background-color: #1F69FA;
border: none;
position: absolute;
}
section container {
height: 200px;
position: relative;
border: 3px solid green;
}
section center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<section>
<div class="container">
<h2> Bubbles </h2>
<button type="button" onclick="next()"> Next </button>
</div>
</section>