【问题标题】:Bootstrap col-md-2 pushes sixth column down the pageBootstrap col-md-2 将第六列下推
【发布时间】:2017-06-29 22:05:18
【问题描述】:

在这里发帖完全是菜鸟,而且我对 Boostrap 的方式也不明智,所以请多多包涵。

我们的网站使用 Bootstrap 3,我被指示创建一个页面,该页面仅使用一个自定义 CSS 文件,我们可以将其与页面打包以与其他公司共享以放在他们的网站上。

我已将我在整个站点中可以找到的所有 col-md-# 样式都复制到自定义 CSS 文件中,并且我没有更改任何边距、宽度等,但是由于某种原因,当我创建了六个使用 col-md-2 样式的文本列,第六列“换行”到新行。

如果我理解正确,我应该能够将六个 col-md-2 放入一行/一行。

我希望我已将我的屏幕打印和代码正确地插入到我的帖子中。

感谢您为这位初学者提供的任何帮助!

2017 年 6 月 29 日更新:我相信我已经发现了问题所在。我没有为 body 和 html 标签包含一些 Bootstrap CSS。一旦我包含了该代码,一切就都到位了。谢谢你,詹尼和托马斯!

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

.row {
  margin-right: -15px;
  margin-left: -15px;
}

.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: 15px;
  padding-left: 15px;
}

@media (min-width: 992px) {
  .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
    float: left;
  }
  .col-md-12 {
    width: 100%;
  }
  .col-md-11 {
    width: 91.66666667%;
  }
  .col-md-10 {
    width: 83.33333333%;
  }
  .col-md-9 {
    width: 75%;
  }
  .col-md-8 {
    width: 66.66666667%;
  }
  .col-md-7 {
    width: 58.33333333%;
  }
  .col-md-6 {
    width: 50%;
  }
  .col-md-5 {
    width: 41.66666667%;
  }
  .col-md-4 {
    width: 33.33333333%;
  }
  .col-md-3 {
    width: 25%;
  }
  .col-md-2 {
    width: 16.66666667%;
  }
  .col-md-1 {
    width: 8.33333333%;
  }
  .col-md-pull-12 {
    right: 100%;
  }
  .col-md-pull-11 {
    right: 91.66666667%;
  }
  .col-md-pull-10 {
    right: 83.33333333%;
  }
  .col-md-pull-9 {
    right: 75%;
  }
  .col-md-pull-8 {
    right: 66.66666667%;
  }
  .col-md-pull-7 {
    right: 58.33333333%;
  }
  .col-md-pull-6 {
    right: 50%;
  }
  .col-md-pull-5 {
    right: 41.66666667%;
  }
  .col-md-pull-4 {
    right: 33.33333333%;
  }
  .col-md-pull-3 {
    right: 25%;
  }
  .col-md-pull-2 {
    right: 16.66666667%;
  }
  .col-md-pull-1 {
    right: 8.33333333%;
  }
  .col-md-pull-0 {
    right: auto;
  }
  .col-md-push-12 {
    left: 100%;
  }
  .col-md-push-11 {
    left: 91.66666667%;
  }
  .col-md-push-10 {
    left: 83.33333333%;
  }
  .col-md-push-9 {
    left: 75%;
  }
  .col-md-push-8 {
    left: 66.66666667%;
  }
  .col-md-push-7 {
    left: 58.33333333%;
  }
  .col-md-push-6 {
    left: 50%;
  }
  .col-md-push-5 {
    left: 41.66666667%;
  }
  .col-md-push-4 {
    left: 33.33333333%;
  }
  .col-md-push-3 {
    left: 25%;
  }
  .col-md-push-2 {
    left: 16.66666667%;
  }
  .col-md-push-1 {
    left: 8.33333333%;
  }
  .col-md-push-0 {
    left: auto;
  }
  .col-md-offset-12 {
    margin-left: 100%;
  }
  .col-md-offset-11 {
    margin-left: 91.66666667%;
  }
  .col-md-offset-10 {
    margin-left: 83.33333333%;
  }
  .col-md-offset-9 {
    margin-left: 75%;
  }
  .col-md-offset-8 {
    margin-left: 66.66666667%;
  }
  .col-md-offset-7 {
    margin-left: 58.33333333%;
  }
  .col-md-offset-6 {
    margin-left: 50%;
  }
  .col-md-offset-5 {
    margin-left: 41.66666667%;
  }
  .col-md-offset-4 {
    margin-left: 33.33333333%;
  }
  .col-md-offset-3 {
    margin-left: 25%;
  }
  .col-md-offset-2 {
    margin-left: 16.66666667%;
  }
  .col-md-offset-1 {
    margin-left: 8.33333333%;
  }
  .col-md-offset-0 {
    margin-left: 0;
  }
}

@media (max-width: 992px) {
  .md-margin-bottom-10 {
    margin-bottom: 10px;
  }
  .md-margin-bottom-20 {
    margin-bottom: 20px;
  }
  .md-margin-bottom-30 {
    margin-bottom: 30px;
  }
  .md-margin-bottom-40 {
    margin-bottom: 40px;
  }
  .md-margin-bottom-50 {
    margin-bottom: 50px;
  }
  .md-margin-bottom-60 {
    margin-bottom: 60px;
  }
}
<div class="container">
<div class="row">
  <div class="col-md-2 md-margin-bottom-40">
      text 1<br>
    text 2
  </div>
  <div class="col-md-2 md-margin-bottom-40">
      text 3<br>
    text 4
  </div>
  <div class="col-md-2 md-margin-bottom-40">
      text 5<br>
    text 6
  </div>
  <div class="col-md-2 md-margin-bottom-40">
      text 7<br>
    text 8
  </div>
  <div class="col-md-2 md-margin-bottom-40">
      text 9<br>
    text 10
  </div>
  <div class="col-md-2 md-margin-bottom-40">
      text 11<br>
    text 12
  </div>
</div>
</div>

【问题讨论】:

  • 您的代码在笔中看起来和工作正常:codepen.io/giannidk/pen/NgXjxO您还有其他包装吗?
  • @gianni 不。我什至将页面及其 CSS 文件复制到了不同的位置,这样它们就不会位于 Bootstrap 站点中,而且它仍然推动第六列,因此它直接出现在第一列下方列而不是第五列的右侧。
  • 这很奇怪,因为我没有更改您的代码中的任何内容,并且在我的笔中它工作正常。某处可能有一些css冲突?
  • 你是从 bootstrap.css 文件中复制 CSS 吗?
  • 是的,您必须从 bootstrap.css 复制 CSS,这在 codepen 中可以正常工作

标签: twitter-bootstrap-3


【解决方案1】:

我的猜测是你有一些冲突的 CSS...对我来说,看起来你正在从 bootstrap.css 复制 CSS,这不需要这样做。

下面是具有 bootstrap 3 设置的代码笔。我已将您的代码直接粘贴到其中,因此您可以看到它确实有效。

https://codepen.io/GuruTom/pen/GEyvrq

使用的代码:

<div class="container">
  <div class="row">
    <div class="col-md-2 md-margin-bottom-40">
      text 1<br>
      text 2
    </div>
    <div class="col-md-2 md-margin-bottom-40">
      text 3<br>
      text 4
    </div>
    <div class="col-md-2 md-margin-bottom-40">
      text 5<br>
      text 6
    </div>
    <div class="col-md-2 md-margin-bottom-40">
      text 7<br>
      text 8
    </div>
    <div class="col-md-2 md-margin-bottom-40">
      text 9<br>
      text 10
    </div>
    <div class="col-md-2 md-margin-bottom-40">
      text 11<br>
      text 12
    </div>
  </div>
</div>

【讨论】:

  • 我将 CSS 从 bootstrap.css 复制到一个独立的自定义 CSS 文件中,我们将与这个网页打包并与其他公司共享,其中大多数公司的网站不使用 Bootstrap ,所以我试图为他们提供他们需要使页面看起来像它应该的CSS。 (我试图在我的帖子中解释这一点,但如果我不清楚,很抱歉。)所以,这个页面我只指向自定义 CSS 文件,我从 boostrap.css 中复制了代码。也许我遗漏了什么?
  • 我强烈建议不要这样做......对于它只是使用 bootstrap.css 的小文件(整个事情)他们不会注意到性能下降,它会为你节省大量和大量的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-15
  • 2019-05-23
  • 2014-08-02
  • 2016-11-09
  • 1970-01-01
  • 2015-06-19
  • 1970-01-01
相关资源
最近更新 更多