P粉7558637502023-09-04 00:28:14
您只需将 top 更改为:
#White_Turm2{ width: 50px; height: 50px; padding: 0px; background: none; border: none; position: relative; top: -100px; left: 350px; } #White_Pawn7{ width: 50px; height: 50px; padding: 0px; background: none; border: none; position: relative; top: -100px; left: 300px; } #White_Pawn8{ width: 50px; height: 50px; padding: 0px; background: none; border: none; position: relative; top: -100px; left: 296px; }
但我建议你使用display:flex;属性,它更容易,并且您不需要编写那么多代码。
#Background_Board {
display:flex;
flex-direction: column;
}
.row {
display:flex;
align-items:center;
justify-content: center;
}
img {
width: 45px;
height: 45px;
vertical-align: middle;
position: relative;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="White.css" />
<link rel="stylesheet" href="Generell.css" />
<title>Chess Game</title>
</head>
<body>
<div id="Background_Board">
<div class="row">
<button id="White_Turm">
<img
src="Pieces/White/White%20Turm.png"
/>
</button>
<button id="White_Horse">
<img
src="Pieces/White/White%20Horse.png"
/>
</button>
<button id="White_Sprinter">
<img
src="Pieces/White/White%20Sprinter.png"
/>
</button>
<button id="White_Queen">
<img
src="Pieces/White/White%20Queen.png"
/>
</button>
<button id="White_King">
<img src="Pieces/White/White%20King.png"/>
</button>
<button id="White_Sprinter2">
<img
src="Pieces/White/White%20Sprinter.png"
/>
</button>
<button id="White_Horse2">
<img
src="Pieces/White/White%20Horse.png"
/>
</button>
<button id="White_Turm2">
<img
src="Pieces/White/White%20Turm.png"
/>
</button>
</div>
<div class="row">
<button id="White_Pawn1">
<img
src="Pieces/White/Bauer%20Weiß.png"
/>
</button>
<button id="White_Pawn2">
<img
src="Pieces/White/Bauer%20Weiß.png"
/>
</button>
<button id="White_Pawn3">
<img
src="Pieces/White/Bauer%20Weiß.png"
/>
</button>
<button id="White_Pawn4">
<img
src="Pieces/White/Bauer%20Weiß.png"
/>
</button>
<button id="White_Pawn5">
<img
src="Pieces/White/Bauer%20Weiß.png"
/>
</button>
<button id="White_Pawn6">
<img
src="Pieces/White/Bauer%20Weiß.png"
/>
</button>
<button id="White_Pawn7">
<img
src="Pieces/White/Bauer%20Weiß.png"
/>
</button>
<button id="White_Pawn8">
<img
src="Pieces/White/Bauer%20Weiß.png"
/>
</button>
</div>
</div>
</body>
</html>