如何包装内联用div的内容,以使包裹的部分占据了以前的内线式div下方的空白空间?
.container {
height: 200px;
width: 200px;
border: 5px solid black;
padding: 5px;
}
.button-group {
display: inline-flex;
flex-wrap: wrap;
}
.box {
height: 45px;
width: 45px;
border-width: 5px;
border-style: solid;
}
.red {
border-color: red;
}
.green {
border-color: green;
}
.blue {
border-color: blue;
}
.yellow {
border-color: yellow;
}
.pink {
border-color: pink;
}
.brown {
border-color: brown;
}
<div class="container">
<div class="button-group">
<div class="box red">R</div>
<div class="box green">G</div>
</div>
<div class="button-group">
<div class="box blue">Bl</div>
<div class="box yellow">Y</div>
</div>
<div class="button-group">
<div class="box pink">P</div>
<div class="box brown">Br</div>
</div>
</div>
实际:
^如果在第一个 box
中只有一个 button组
和两个 box
在第二个按钮组然后所有三个都占据了第一行。但是,一旦您将第三个
box
添加到第二个按钮组
时,其所有三个 box
移动到下一行。我希望 box
不再发生这种情况,无论它们属于哪种 button> button> button
。
预期:
总体期望: n container
和 m
。任何内部的内联用divs数>盒子
<代码>按钮组按钮组
或任何 box
都可以动态删除。最后,每行上必须有三个 box
,或尽可能多的WRT到可用的宽度。
谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
显示:内容
并移动显示:flex 到容器Remove the button-group using
display:contents
and movedisplay:flex
to the container如果您删除flex并将纽扣组显示内联,但他们的孩子显示内联块(因此他们都显示内线并占用给定的维度),您将获得所需的结果。
更新:要删除框之间的空间,请设置并重置字体大小如下:
If you remove the flex and make the button-groups display inline but their children display inline-block (so they both display inline and take up the given dimensions) you get the required result.
UPDATE: to remove the space between the boxes, set and reset the font-sizes as below: