Boostrap拉右导致元素重叠 [英] Boostrap pull-right causing element overlap

查看:113
本文介绍了Boostrap拉右导致元素重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我将一个右键类添加到按钮上时, (或包含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.

Updated Example

<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.

Example Here

<div class="text-right">
    <button type="button" class="btn btn-default">Add</button>
</div>

这篇关于Boostrap拉右导致元素重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆