我正在做一个学校项目,我需要在屏幕的4个象限中放置4个按钮。然而,第一个按钮在它和屏幕顶部以及侧面之间有一个很小的差距。
代码:
game.html
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>Game</title>
<link rel="stylesheet" href="css/game.css">
</head>
<body>
<div id="container">
<button class="button">A</button>
<button class="button">B</button>
<button class="button">C</button>
<button class="button">D</button>
</div>
</body>
</html>game.css
body {
background-color: black;
overflow: hidden;
position: fixed;
}
h1, h2 {
color: white;
font-family: Ubuntu Mono;
}
#container {
width: 100%;
min-height: 100%;
height: 100%;
}
.button {
border: none;
color: white;
width: 50%;
height: 50vh;
text-align: center;
text-decoration: none;
display: inline-block;
font-family: Ubuntu Mono;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
position: fixed;
}
.button: nth-child(1) {
background-color: #bf0000;
top: 0;
left: 0;
}
.button:nth-child(2) {
background-color: #001fbf;
top: 0;
right: 0;
}
.button:nth-child(3) {
background-color: #e6c52d;
bottom: 0;
left: 0;
}
.button:nth-child(4) {
background-color: #1fbf1f;
bottom: 0;
right: 0;
}但是,我在这里看到了输出:

我怎样才能消除第一个按钮的间隙?
(如果你想要的话,帮我看看颜色:D)
如有任何帮助,将不胜感激!
发布于 2022-02-10 20:48:31
这是CSS中的一个错误。
.button:nth-child(1) {
background-color: #bf0000;
top: 0;
left: 0;
}删除.button后的空格:
https://stackoverflow.com/questions/71071864
复制相似问题