原来我们骰子的各个面,可以用定位position来做。当我们学习了弹性盒子,我们就可用flex来实现。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
div {
width: 100px;
height: 100px;
background: #ccc;
border-radius: 20px;
box-shadow: 2px 2px 1px 1px #000;
margin: 50px;
display: flex;
}
span {
width: 20px;
height: 20px;
background: black;
border-radius: 10px;
}
p {
display: flex;
}
.box1 {
justify-content: center;
align-items: center;
}
.box2 {
justify-content: space-between;
}
.box2 span {
margin: 10px;
}
.box2 span:nth-child(2) {
align-self: flex-end;
}
.box3 {
justify-content: space-around;
}
.box3 span {
margin: 5px;
}
.box3 span:nth-child(2) {
align-self: center;
}
.box3 span:nth-child(3) {
align-self: flex-end;
}
.box4 {
flex-direction: column;
justify-content: space-between;
}
.box4 p {
justify-content: space-between;
}
.box4 span {
margin: 5px;
}
.box5 {
flex-direction: column;
justify-content: space-between;
}
.box5 p {
justify-content: space-between;
}
.box5 span {
margin: 5px;
}
.box5 p:nth-of-type(2) {
justify-content: center;
}
.box6 {
flex-direction: column;
justify-content: space-around;
}
.box6 p {
justify-content: space-around;
}
</style>
</head>
<body>
<div class="box1">
<span></span>
</div>
<div class="box2">
<span></span>
<span></span>
</div>
<div class="box3">
<span></span>
<span></span>
<span></span>
</div>
<div class="box4">
<p>
<span></span>
<span></span>
</p>
<p>
<span></span>
<span></span>
</p>
</div>
<div class="box5">
<p>
<span></span>
<span></span>
</p>
<p>
<span></span>
</p>
<p>
<span></span>
<span></span>
</p>
</div>
<div class="box6">
<p>
<span></span>
<span></span>
</p>
<p>
<span></span>
<span></span>
</p>
<p>
<span></span>
<span></span>
</p>
</div>
</body>
</html>