我一直用浮动。认识到也许它不是最好的方法。尝试使用相对位置。为什么 myDiv 的孩子不互相忽略 top ?因为它不是 inline-block ?
<div class="myDiv">
<div class="myDiv1"></div>
<div class="myDiv2"></div>
<div class="myDiv3"></div>
<div class="myDiv4"></div>
</div>
.myDiv
{
float: left;
margin-left: 10px;
margin-top: 10px;
width: 100px;
height: 100px;
background-color: grey;
}
.myDiv1
{
background-color: green;
width: 10px;
height: 10px;
position: relative;
top: 10px;
left: 10px;
}
.myDiv2
{
background-color: red;
width: 10px;
height: 10px;
position: relative;
top: 0px;
left: 30px;
}
.myDiv3
{
background-color: blue;
width: 10px;
height: 10px;
position: relative;
top: 0px;
left: 50px;
}
.myDiv4
{
background-color: yellow;
width: 10px;
height: 10px;
position: relative;
top: 0px;
left: 70px;
}