twitter-bootstrap 我应该只有一个 Bootstrap 3 容器吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23062439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Am I only supposed to have one Bootstrap 3 container?
提问by Josh
I'm trying to figure out Bootstrap 3 and having lots of trouble. The Bootstrap 3 site says:
我正在尝试弄清楚 Bootstrap 3 并且遇到了很多麻烦。Bootstrap 3 网站说:
Easily center a page's contents by wrapping its contents in a .container. Containers set width at various media query breakpoints to match our grid system.
Note that, due to padding and fixed widths, containers are not nestable by default.
通过将页面内容包装在 .container 中,轻松地将页面内容居中。容器在各种媒体查询断点处设置宽度以匹配我们的网格系统。
请注意,由于填充和固定宽度,默认情况下容器不可嵌套。
The former line seems to support this, as I wouldn't want nested containers to re-set the width to more than the parent. That latter line makes me think that I should only have one container on a page (or siblings at most), regardless of fluid/normal/etc., without doing something "extra".
前一行似乎支持这一点,因为我不希望嵌套容器将宽度重新设置为大于父级的宽度。后一行让我觉得我应该在一个页面上只有一个容器(或最多兄弟姐妹),而不管流体/正常/等,而不做任何“额外”的事情。
Is that correct?
那是对的吗?
回答by Marco Slooten
You are correct in that you do not want to nest the .containers. However, there are plenty of cases where you would have multiple containers. For instance, if you want to have a full width element (screen width, not container width). This is perfectly fine:
您是对的,因为您不想嵌套 .containers。但是,在很多情况下您会拥有多个容器。例如,如果您想要一个全宽元素(屏幕宽度,而不是容器宽度)。这完全没问题:
<div class="container">
<div class="col-md-12">
<p>Content</p>
</div>
</div>
<div id="full-width-element">
<p>Other content, stretching full width of the page</p>
</div>
<div class="container">
<div class="col-md-12">
<p>Content</p>
</div>
</div>
Take a look at the examples on the Bootstrap site: http://getbootstrap.com/getting-started/#examples, they use multiple .containers as well.
查看 Bootstrap 站点上的示例:http: //getbootstrap.com/getting-started/#examples,它们也使用多个 .containers。
So nesting container is not a good idea without modification or careful consideration. Using multiple containers is fine (otherwise it should have been an ID instead of a class as well)!
因此,如果不进行修改或仔细考虑,嵌套容器不是一个好主意。使用多个容器很好(否则它也应该是一个 ID 而不是一个类)!

