页面的布局
准备一个html页面
<!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">
<title>贪吃蛇</title>
</head>
<body>
<!-- 主游戏界面 -->
<div id="main">
<!-- 蛇的舞台 -->
<div id="stage">
<!-- 蛇 -->
<div id="snake">
<div></div>
</div>
<!-- 食物 -->
<div id="food">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
<!-- 积分面板 -->
<div id="sope-panel">
<div>SCORE:<span id="score">3</span></div>
<div>LEVEL:<span id="level">0</span></div>
</div>
</div>
</body>
</html>
为页面编写样式(这里我们使用less预编译器来编写我们的样式)
@color:darkcyan;
*{
margin: 0;
padding: 0;
}
body{
font: bold 20px "Courier";
}
#main{
width: 360px;
height: 420px;
box-sizing: border-box;
background-color: aquamarine;
border-radius: 15px;
border: 10px solid @color;
margin: 10px auto;
display: flex;
flex-flow: column;
justify-content: space-around;
align-items: center;
#stage{
width: 300px;
height: 300px;
border: 1px solid #000;
position: relative;
#snake{
&>div{
width: 10px;
height: 10px;
background: #000;
border:1px solid @color;
position: absolute;
}
}
#food{
width: 10px;
height: 10px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
position: absolute;
left: 40px;
top: 100px;
&>div{
width: 4px;
height: 4px;
background: #000;
transform: rotate(60deg);
}
}
}
#sope-panel{
width: 304px;
display: flex;
justify-content: space-between;
}
}
页面效果