请看下面的例子。我正在尝试将yellow
div放在red
div下面和green
下半部分的左侧。如果我使用clear: left
它会跳下来,但它会留下空的空间。我想要它填补这个空间。
这是一个例子: https://jsfiddle.net/enqqr2w8/
答案 0 :(得分:0)
#redyellow
{
width: 100px;
height: 200px;
float: left;
}
#red
{
width: 100px;
height: 100px;
background-color: red;
float: left;
}
#green
{
width: 100px;
height: 200px;
background-color: green;
float: left;
}
#blue
{
width: 100px;
height: 100px;
background-color: blue;
float: left;
}
#yellow
{
width: 100px;
height: 100px;
background-color: yellow;
float: left;
}
body
{
width: 300px;
}

<body>
<div id="redyellow">
<div id="red">
aa
</div>
<div id="yellow">
aa
</div>
</div>
<div id="green">
aa
</div>
<div id="blue">
aa
</div>
</body>
&#13;
这对你有用吗?
编辑:我找到了一种只用CSS3制作动态列的方法:
div
{
width: 100px;
height: 100px;
break-inside: avoid-column;
}
#red {
background-color: red;
}
#green
{
height: 200px;
background-color: green;
}
#blue
{
background-color: blue;
}
#yellow
{
background-color: yellow;
}
#orange
{
background-color: orange;
}
#black
{
background-color: black;
}
body
{
width: 300px;
columns: 3;
}
&#13;
<body>
<div id="red"></div>
<div id="yellow"></div>
<div id="green"></div>
<div id="blue"></div>
<div id="orange"></div>
</body>
&#13;