我正在做一個學校專案,我需要在螢屏的 4 個象限中放置 4 個按鈕。但是,第一個按鈕與螢屏頂部以及側面之間有一點間隙。
代碼:
游戲.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>
游戲.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)
任何幫助表示贊賞!:D
uj5u.com熱心網友回復:
這是 CSS 中的一個錯字。
.button:nth-child(1) {
background-color: #bf0000;
top: 0;
left: 0;
}
洗掉 .button 后的空格:
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/425241.html
上一篇:使用其內容定位按鈕
