我一直在尝试制作一款游戏,用户必须按下该按钮才能重定向到游戏页面。
我是HTML / CSS的新手,我希望按钮位于标题的下面,但是按钮却转到标题的侧面。
我尝试在标题后使用<br>
标记,尝试使用position:fixed
并指定顶部和底部的高度(此方法可行,但是对于不同的屏幕尺寸,按钮移到了不正确的位置),并且我尝试更改display:block
,但无济于事。
这是我的代码:
h {
color: rgb(0, 0, 0);
text-shadow: 1px 2px 5px black;
text-align: center;
font-family: 'Times New Roman', Times, serif;
font-size: 30pt;
}
div {
text-align: center;
height: 100%;
width: 100%;
display: flex;
position: fixed;
align-items: center;
justify-content: center;
margin: 0;
padding: 0;
}
.button {
float: left;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.2), 0 2px 5px 0 rgba(0, 0, 0, 0.19);
-webkit-transition-duration: 0.4s;
/* Safari */
transition-duration: 0.4s;
background-color: #97d9f3;
border-color: rgb(0, 131, 192);
border-style: solid;
color: black;
padding: 15px 32px;
display: block;
font-size: 16px;
}
.button:hover {
background-color: rgb(90, 190, 236);
}
body {
text-align: center;
height: 100%;
width: 100%;
display: flex;
position: fixed;
align-items: center;
justify-content: center;
background-color: #84ceeb;
margin: 0;
padding: 0;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</div2>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h>
Un Jeu de Veux Tu Danser
</h>
<button class="button" onclick="window.location.href='game.html'">Commencer</button>
<script src="script.js"></script>
</body>
</html>
当您在基于flex的父元素上使用flex-direction: column;
时,每个子元素都将沿y轴渲染。
h {
color: rgb(0, 0, 0);
text-shadow: 1px 2px 5px black;
text-align: center;
font-family: 'Times New Roman', Times, serif;
font-size: 30pt;
}
div {
text-align: center;
height: 100%;
width: 100%;
display: flex;
position: fixed;
align-items: center;
justify-content: center;
margin: 0;
padding: 0;
}
.button {
float: left;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.2), 0 2px 5px 0 rgba(0, 0, 0, 0.19);
-webkit-transition-duration: 0.4s;
/* Safari */
transition-duration: 0.4s;
background-color: #97d9f3;
border-color: rgb(0, 131, 192);
border-style: solid;
color: black;
padding: 15px 32px;
display: block;
font-size: 16px;
}
.button:hover {
background-color: rgb(90, 190, 236);
}
body {
text-align: center;
height: 100%;
width: 100%;
display: flex;
position: fixed;
align-items: center;
justify-content: center;
background-color: #84ceeb;
margin: 0;
padding: 0;
flex-direction: column; /* added */
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</div2>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h>
Un Jeu de Veux Tu Danser
</h>
<button class="button" onclick="window.location.href='game.html'">Commencer</button>
<script src="script.js"></script>
</body>
</html>