如何用内容填充整个Bootstrap行

时间:2015-09-25 03:04:25

标签: html css twitter-bootstrap row twitter-bootstrap-2

我试图找出如何让3个子span4s填充引导行的整个宽度。看起来在最后的span4之后还剩下空间。上次我检查3 x 4是12,所以我错过了什么?

<body>
    <div class="container">
        <div class="row" style="background-color:#eee; border: 1px solid #888;">
            <input name="srcCity" type="text" class="span4" placeholder="City">
            <select name="srcState" class="span4" data-country="US" data-state="CA"> </select>
            <input  name="srcZip" type="text" class="span4" placeholder="Zip">
        </div>
    </div>
</body>

https://jsfiddle.net/ujq2vxqc/

2 个答案:

答案 0 :(得分:1)

我认为您使用的是错误的类,而是使用span4(在bootstrap.css文件AFAIK中不存在),col-xx-4xx xs可以sm,{ {1}},mdlg由你决定 有点像:

    <body>
    <div class="container">
        <div class="row" style="background-color:#eee; border: 1px solid #888;">
            <input name="srcCity" type="text" class="col-sm-4" placeholder="City">
            <select name="srcState" class="col-sm-4" data-country="US" data-state="CA"> </select>
            <input  name="srcZip" type="text" class="col-sm-4" placeholder="Zip">
        </div>
    </div>
</body>

答案 1 :(得分:0)

亨利说你需要使用class="col-sm-4"。 默认情况下,容器的填充为15px,您需要在样式表中覆盖它。屏幕宽度依赖于.col-xs-X .col-sm-X .col-md-X .col-lg-X,视野越宽,您想要使用的列越大。

@media size在bootstrap中也很重要。所以假设你有一个768px视图,bootstrap中的容器设置为750px。如下所示。

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}
@media (min-width: 768px) {
  .container {
    width: 750px;
  }
}
@media (min-width: 992px) {
  .container {
    width: 970px;
  }
}
@media (min-width: 1200px) {
  .container {
    width: 1170px;
  }
}
.container-fluid {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

原始

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

让它像这样:

.container {       padding-right:2px;       padding-left:2px;       margin-right:auto;       margin-left:auto;     }

.container {
  padding-right: 2px;
  padding-left: 2px;
  margin-right: auto;
  margin-left: auto;
}
.col-xs-1,
.col-sm-1,
.col-md-1,
.col-lg-1,
.col-xs-2,
.col-sm-2,
.col-md-2,
.col-lg-2,
.col-xs-3,
.col-sm-3,
.col-md-3,
.col-lg-3,
.col-xs-4,
.col-sm-4,
.col-md-4,
.col-lg-4,
.col-xs-5,
.col-sm-5,
.col-md-5,
.col-lg-5,
.col-xs-6,
.col-sm-6,
.col-md-6,
.col-lg-6,
.col-xs-7,
.col-sm-7,
.col-md-7,
.col-lg-7,
.col-xs-8,
.col-sm-8,
.col-md-8,
.col-lg-8,
.col-xs-9,
.col-sm-9,
.col-md-9,
.col-lg-9,
.col-xs-10,
.col-sm-10,
.col-md-10,
.col-lg-10,
.col-xs-11,
.col-sm-11,
.col-md-11,
.col-lg-11,
.col-xs-12,
.col-sm-12,
.col-md-12,
.col-lg-12 {
  position: relative;
  min-height: 1px;
  padding-right: 2px;
  padding-left: 2px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row" style="background-color:#eee; border: 1px solid #888;">

    <div class="col-xs-4">
      <input name="srcCity" type="text" class="form-control col-lg-4" placeholder="City">
    </div>
    <div class="col-xs-4">
      <select name="srcState" data-country="US" class="form-control col-lg-4" data-state="CA"></select>
    </div>
    <div class="col-xs-4">
      <input name="srcZip" type="text" class="form-control col-lg-4" placeholder="Zip">

    </div>
  </div>

Fiddle