[英]How can I get a <div> to float on top of two other <div>s if the space is too narrow for all three to stay side-by-side?
I have a progress bar consisting of two <div>
s side by side, floated to the right inside a <dd>
.我有一个由两个
<div>
并排组成的进度条,在<dd>
内浮动到右侧。 To the left of the progress bar, I have some text inside another <div>
.在进度条的左侧,我在另一个
<div>
中有一些文本。 If the <dd>
gets too narrow, I want the <div>
containing text to go on top of the progress bar, and not break into two lines.如果
<dd>
太窄,我希望<div>
包含文本到进度条顶部的 go,而不是分成两行。
I am using bootstrap.css with no modifications:我正在使用 bootstrap.css 没有修改:
.col-6 { -ms-flex: 0 0 50%; flex: 0 0 50%; max-width: 50%; position: relative; width: 100%; padding-right: 15px; padding-left: 15px; }.my-0 { margin-top: 0;important. }:py-2 { padding-top. 0;5rem.important: };float-left { float. left:important; }.float-right { float: right;important. }:bg-success { background-color; #28a745 !important; } .bg-danger { background-color: #dc3545 !important; }
<dd class="col-6 my-0"> <div class="float-left">Some text</div> <div class="py-2 float-right bg-success" style="width:10px;"></div> <div class="py-2 float-right bg-danger" style="width:90px;"></div> </dd>
I have tried adding z-index
to the <div>
s, but haven't been able to acheive the effect I want.我尝试将
z-index
添加到<div>
,但无法达到我想要的效果。
How to do?怎么做?
You can do it with flex
I think.我认为你可以用
flex
来做到这一点。
Look at your code.看看你的代码。
<dd class="col-6 my-0">
<div class="d-flex">
<div class="float-left">Some text</div>
<div class="ml-auto">
<div class="py-2 float-right bg-success" style="width:10px;"></div>
<div class="py-2 float-right bg-danger" style="width:90px;"></div>
</div>
</div>
</dd>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.