简体   繁体   English

如何使用Bootstrap减少两列之间的空间

[英]How to reduce too much space between two columns with Bootstrap

There is too much space between two form-groups, if i reduce the column size of the first one it goes on next line which i don't want. 两个表单组之间的空间太大,如果我减小第一个表单组的列大小,它将在我不希望的下一行进行。 I would like email address to be closer to phone extension. 我希望电子邮件地址更接近电话分机号。 Is there any way to do this without moving email address field with css left margins? 有什么方法可以做到这一点,而无需移动电子邮件地址字段,而使CSS留有空白?

在此处输入图片说明

    <div class="row">
        <div class="form-group col-md-5">
            <label for="telephoneNumber">Telephone Number</label>
            <div class="form-inline">
                <input type="text" class="form-control" id="telephoneNumber1" maxlength="3" size="3">-
                <input type="text" class="form-control" id="telephoneNumber2" maxlength="3" size="3">-
                <input type="text" class="form-control" id="telephoneNumber3" maxlength="3" size="3">Ext
                <input type="text" class="form-control" id="extension" maxlength="3" size="3">

            </div>
        </div>
        <div class="form-group col-md-4">
            <label for="emailAddress">Email Address</label>
            <input type="text" class="form-control" id="emailAddress">
        </div>
    </div>

The total number of columns on a row is equal to 12. 行上的总列数等于12。

You have set the class .col-md-5 on your first column which means it would take about 50% of the available width. 您已经在第一栏中设置了类.col-md-5 ,这意味着它将占用可用宽度的大约50%。 And your next column starts immediately after that. 之后,您的下一列立即开始。 A solution would be to set a class with fewer column on your first form-group, let's say col-md-3 . 一种解决方案是在第一个表单组上设置一个列数较少的类,比方说col-md-3 Here's a demo: http://output.jsbin.com/tipusi/1/ 这是一个演示: http : //output.jsbin.com/tipusi/1/

<!-- HTML -->
<div class="row">
    <div class="form-group col-md-12">
      <div class="inline-block">
          <label for="telephoneNumber">Telephone Number</label>
              <div class="form-inline">
                <input type="text" class="form-control" id="telephoneNumber1" maxlength="3" size="3">-
                <input type="text" class="form-control" id="telephoneNumber2" maxlength="3" size="3">-
                <input type="text" class="form-control" id="telephoneNumber3" maxlength="3" size="3">Ext
                <input type="text" class="form-control" id="extension" maxlength="3" size="3">
              </div>
      </div>
      <div class="inline-block">
          <label for="emailAddress">Email Address</label>
          <input type="text" class="form-control" id="emailAddress">
      </div>
    </div>
</div>

<!-- CSS-->
.inline-block {display: inline-block;}
<div class="row">
    <div class="form-group col-md-5 no-padding">
        <label for="telephoneNumber">Telephone Number</label>
        <div class="form-inline">
            <input type="text" class="form-control" id="telephoneNumber1" maxlength="3" size="3">-
            <input type="text" class="form-control" id="telephoneNumber2" maxlength="3" size="3">-
            <input type="text" class="form-control" id="telephoneNumber3" maxlength="3" size="3">Ext
            <input type="text" class="form-control" id="extension" maxlength="3" size="3">

        </div>
    </div>
    <div class="form-group col-md-4 no-padding">
        <label for="emailAddress">Email Address</label>
        <input type="text" class="form-control" id="emailAddress">
    </div>
</div>

Add below css class 在css类下面添加

.less-padding {
   padding: 10px !important;
   margin: 10px !important;
}
.no-padding {
   padding: 0 !important;
   margin: 0 !important;
}

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

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