twitter-bootstrap 如何防止浮动的div中断?(引导程序)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16762164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prevent break in div with float right? (bootstrap)
提问by Arturo Hernandez
I have the following HTML. And the text (tidbit) on the right keeps dropping off to the next line. This is in chrome. Is there a way to keep what is inside of the pull-right div together in one line? here is the jsFiddle.
我有以下 HTML。右侧的文本(花絮)不断下降到下一行。这是镀铬的。有没有办法将右拉 div 中的内容保持在一行中?这是jsFiddle。
<div class="container" style="width:500px;>
<div class="controls controls-row">
<span class="add-on">This can be quite long</span>
<div class="pull-right">
<input class="input-mini" name="Amount" type="number" />
<button type="button" class="btn" style="margin-bottom: 10px">Add</button>
<div style="text-align:right; width:40px;">tidbit</div>
</div>
</div>
</diV>
采纳答案by Dhiraj
You can perhaps add pull-left and pull-right inside the pull-right parent container
您也许可以在 pull-right 父容器中添加 pull-left 和 pull-right
<div class="container" style="width:500px;">
<div class="controls controls-row"> <span class="add-on">This can be quite long</span>
<div class="pull-right">
<div class="pull-left">
<input class="input-mini" name="Amount" type="number" />
<button type="button" class="btn" style="margin-bottom: 10px">Add</button>
</div>
<div class="pull-right" style="text-align:right; width:40px;">tidbit</div>
</div>
</div>
</diV>
Hope this helps
希望这可以帮助
回答by Sirko
You can do this with two corrections:
您可以通过两个更正来做到这一点:
- Set
display: inline-blockin the "tidbit" div. - Set
white-space: nowrapto thepull-rightcontainer.
- 设置
display: inline-block在“花絮”div 中。 - 设置
white-space: nowrap到pull-right容器。
<div class="container" style="width:500px;>
<div class="controls controls-row">
<span class="add-on">This can be quite long</span>
<div class="pull-right">
<input class="input-mini" name="Amount" type="number" />
<button type="button" class="btn" style="margin-bottom: 10px">Add</button>
<div style="text-align:right; width:40px; display: inline-block;">tidbit</div>
</div>
</div>
</diV>
.pull-right{
white-space:nowrap;
}
回答by Duncan Walker
Remove the div tag around tidbit and, if necessary, wrap the tidbit in a span - JSfiddle
删除tidbit周围的 div 标签,如有必要,将tidbit包裹在一个 span 中 - JSfiddle
<div class="container" style="width:500px;>
<div class="controls controls-row">
<span class="add-on">This can be quite long</span>
<div class="pull-right">
<input class="input-mini" name="Amount" type="number" />
<button type="button" class="btn" style="margin-bottom: 10px">Add</button>
<span>tidbit</span><!--Move this the before or after the button-->
</div>
</div>
</diV>
回答by ubaid ashraf
What is the combined width of div class pullright controls. It is exceeding 500px i think.
div 类 pullright 控件的组合宽度是多少。我认为它超过了 500px。
If width of these 3 exceeds 500px, tidbit text will move to next line. So control width
如果这 3 个的宽度超过 500px,花絮文本将移动到下一行。所以控制宽度

