简体   繁体   English

Twitter Bootstrap:填充100%的网格宽度会包裹元素

[英]Twitter Bootstrap: Filling 100% grid width wraps elements

I have a problem that when using the Twitter Bootstrap Grid system the elements contained in the grid are wrapped around the end of the row, although the width of all the contained elements together is 100%. 我有一个问题,当使用Twitter Bootstrap网格系统时,网格中包含的元素被包裹在行的末尾,尽管所有包含的元素的宽度总计为100%。

Illustration here: http://www.bootply.com/KEm1U4bDVP 此处的插图: http : //www.bootply.com/KEm1U4bDVP

I tried to find for margins and paddings already but couldn't find any element that makes up that extra space to cause the wraparound. 我已经尝试查找边距和填充,但是找不到任何组成额外空间以引起环绕的元素。

Instead of using "30%" width for the last button I could use a value like 29%, but that is against my will. 我可以使用29%之类的值代替最后一个按钮使用“ 30%”的宽度,但这违反了我的意愿。 since the little extra spacing is becoming less and less when the screen width decreases. 因为当屏幕宽度减小时,很少的额外间隔变得越来越少。

How can I make the buttons to stay on one row and not be wrapped? 如何使按钮停留在一行上而不被包裹?

Buttons are inline-block elements. 按钮是行内块元素。 You have two options: 您有两种选择:

Floated elements: http://www.bootply.com/drrFPKsDPY 浮动元素: http//www.bootply.com/drrFPKsDPY

Or comment the spaces: http://www.bootply.com/RMoQw95WpJ 或注释空格: http : //www.bootply.com/RMoQw95WpJ

You have to use the grid-system correctly 您必须正确使用网格系统

<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
          <div class="row">
            <div class="col-lg-4"><button class="btn btn-primary btn-block">1</button></div>
            <div class="col-lg-4"><button class="btn btn-primary btn-block">1</button></div>
            <div class="col-lg-4"><button class="btn btn-primary btn-block">1</button></div>
          </div>
        </div>
    </div>
</div>

You can set the width using calc see fiddle: https://jsfiddle.net/eye4ytq2/1/ 您可以使用calc设置宽度,请参见小提琴: https//jsfiddle.net/eye4ytq2/1/

<button class="btn btn-primary" style="width: calc(30% - 5px)">1</button>
<button class="btn btn-primary" style="width: 40%">2</button>
<button class="btn btn-primary" style="width: calc(30% - 5px)">3</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM