推荐答案
留出空格的原因是为justify-content
属性指定了center
值.下图显示了将justify-content
属性设置为center
时容器的行为.
下图演示了导致Chrome Dev工具出现差距的功能.
在下面的应用程序中,#snake-container
块中的justify-content
属性已被删除.
<html>
<head>
<style>
* {
margin: 0px;
padding: 0px;
}
#snake-container {
width: 100%;
height: 100%;
display: flex;
}
#tiles {
width: 500px;
height: 500px;
}
.tile {
width: 20px;
height: 20px;
background-color: black;
}
</style>
<title>Snake</title>
</head>
<body>
<div id="snake-container">
<div id="tiles"></div>
</div>
</body>
<script>
for (let i = 0; i < 625; i++) {
const tile = document.createElement("div");
tile.classList.add("tile");
document.getElementById("tiles").appendChild(tile);
}
</script>
</html>