理解 Bootstrap 3中的网格类(colsm-# 和 collg-#)

我正在开始使用 Bootstrap 3,但是在理解如何使用网格类方面遇到了一些困难。

以下是我目前为止的发现:

col-sm-#col-lg-#类似乎不同于普通的老式 col-#,因为它们只适用于屏幕大于一定大小(分别为768px 和992px)的情况。如果省略-sm-or-lg-div 将永远不会折叠成一列。

然而,当我在一行中创建两个 div 时,它们都是 col-sm-6,当窗口的宽度在768px 和992px 之间时,它们似乎是并排的 只有。换句话说,如果我一直缩小窗口,然后慢慢扩大它,布局是单列,然后两列,然后回到单列 再来一次

  1. 这是预期的行为吗?
  2. 如果我想要两列超过768px 的内容,我应该应用 都有类吗? (<div class="col-sm-6 col-lg-6">)
  3. 应该包括 col-6 还有
133609 次浏览

[UPDATE BELOW]

I took another look at the docs and it appears I overlooked a section which talks specifically about this.

The answers to my questions:

  1. Yes, they are meant to apply only to specific ranges, rather than everything above a certain width.

  2. Yes, the classes are meant to be combined.

  3. It appears that this is appropriate in certain cases but not others because the col-# classes are basically equivalent to col-xsm-# or, widths above 0px (all widths).

Other than reading the docs too quickly, I think I was confused because I came into Bootstrap 3 with a "Bootstrap 2 mentality". Specifically, I was using the (optional) responsive styles (bootstrap-responsive.css) in v2 and v3 is quite different (for the better IMO).

UPDATE for stable release:

This question was originally written when RC1 was out. They made some major changes in RC2 so for anyone reading this now, not everything mentioned above still applies.

As of when I'm currently writing this, the col-*-# classes DO seem to apply upwards. So for example, if you want an element to be 12 columns (full width) for phones, but two 6 columns (half page) for tablets and up, you would do something like this:

<div class="col-xs-12 col-sm-6"> ... //NO NEED FOR col-md-6 or col-lg-6

(They also added an additional xs break point after this question was written.)

"If I want two columns for anything over 768px, should I apply both classes?"

This should be as simple as:

<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6"></div>
</div>

No need to add the col-lg-6 too.

Demo: http://www.bootply.com/73119

Here you have a very good tutorial, that explains, how to use the new grid classes in Bootstrap 3.

It also covers mixins etc.

The best way to understand is to simply think from top to bottom ( Large Desktops to Mobile Phones)

Firstly, as B3 is mobile first so if you use xs then the columns will be same from Large desktops to xs ( i recommend using xs or sm as this will keep everything the way you want on every screen size )

Secondly if you want to give different width to columns on different devices or resolutions, than you can add multiple classes e.g

the above will change the width according to the screen resolutions, REMEMBER i am keeping the total columns in each class = 12

I hope my answer would help!

To amend SDP's answer above, you do NOT need to declarecol-xs-12 in <div class="col-xs-12 col-sm-6">. Bootstrap 3 is mobile-first, so every div column is assumed to be a 100% width div by default - which means at the "xs" size it is 100% width, it will always default to that behavior regardless of what you set at sm, md, lg. If you want your xs columns to be not 100%, then you normally do a col-xs-(1-11).

This might be late as I think most of us are using BS4. This article explained all the questions you asked in a detailed and simple manner also includes what to do when. The detailed guide to use bs4 or bootstrap

https://uxplanet.org/how-the-bootstrap-4-grid-works-a1b04703a3b7