Boostrap拉右导致元素重叠 [英] Boostrap pull-right causing element overlap
问题描述
当我将一个右键类添加到按钮上时, (或包含div),则按钮被列表重叠。
< div>
< div class =pull-right>
< button type =buttonclass =btn btn-default>添加< / button>
< / div>
< ul class =list-group>
< li class =list-group-item>有点东西1< / li>
< li class =list-group-item>有点东西2< / li>
< li class =list-group-item>有点东西2< / li>
< / ul>
< / div>
jsfiddle: http://jsfiddle.net/paulbau/384YH/
您应该添加 pull-right
类改为按钮
元素,然后向父元素添加一个clearfix。这样, div
将不会自行折叠。
< div class = clearfix>
< button type =buttonclass =btn btn-default pull-right>添加< / button>
< / div>
或者,由于按钮
是 inline-block
级别元素,可以避免浮动,并使用 text-align:right
。只需将类 text-right
添加到父级。您不再需要clearfix,因为按钮
元素未从文档流中删除。
< button type =buttonclass =btn btn-default>添加< / button>
< / div>
I am trying to get a single button positioned above a list, but with the button to the right.
When I add the pull-right class to the button (or a containing div) the button is then overlapped by the list.
<div>
<div class="pull-right">
<button type="button" class="btn btn-default">Add</button>
</div>
<ul class="list-group">
<li class="list-group-item">Something something 1</li>
<li class="list-group-item">Something something 2</li>
<li class="list-group-item">Something something 2</li>
</ul>
</div>
jsfiddle: http://jsfiddle.net/paulbau/384YH/
You should add the pull-right
class to the button
element instead and then add a clearfix to the parent element. In doing so, the div
won't collapse upon itself.
<div class="clearfix">
<button type="button" class="btn btn-default pull-right">Add</button>
</div>
Alternatively, since the button
is an inline-block
level element, you could avoid floating it and use text-align:right
instead. Just add the class text-right
to the parent. You no longer need the clearfix because the button
element isn't being removed from the document flow.
<div class="text-right">
<button type="button" class="btn btn-default">Add</button>
</div>
这篇关于Boostrap拉右导致元素重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!