CSS 带有固定包装器的 Bootstrap 网格 - 防止列堆积

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18715955/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:19:02  来源:igfitidea点击:

Bootstrap grid with fixed wrapper - Prevent columns from stacking up

csstwitter-bootstrapgridweb-deploymenttwitter-bootstrap-3

提问by John

As the title says I'm trying to use Bootstrap 3 grid system with a fixed wrapper. But when I resize the Browser the columns stack up even if the wrapper stays the same size?

正如标题所说,我正在尝试使用带有固定包装器的 Bootstrap 3 网格系统。但是当我调整浏览器的大小时,即使包装器保持相同的大小,列也会堆叠?

BTW: I'm using version 3 so that I can move to a responsive layout after I have ported the site. (Which is huge and I'm alone, so step by step is the only option ...)

顺便说一句:我正在使用第 3 版,以便在移植网站后可以移动到响应式布局。(这是巨大的,我一个人,所以一步一步是唯一的选择......)

    <!DOCTYPE html>
    <html>
      <head>
        <title>Bootstrap 101 Template</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- Bootstrap -->
        <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">

        <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
          <script src="../../assets/js/html5shiv.js"></script>
          <script src="../../assets/js/respond.min.js"></script>
        <![endif]-->

        <style>
                /* Custom container */
                .container-fixed {
                  margin: 0 auto;
                  max-width: 800px;
                  min-width: 800px;
                  width: 800px;
                                      background-color:#C05659;
                }
                .container-fixed > hr {
                  margin: 30px 0;
                }
        </style>
      </head>
      <body>
            <div class="container-fixed">
                <div class="row">
                  <div class="col-md-4">.col-md-4</div>
                  <div class="col-md-4">.col-md-4</div>
                  <div class="col-md-4">.col-md-4</div>
                </div>
                <hr>
            </div>

        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="http://code.jquery.com/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
      </body>
    </html>

回答by Zim

The sm,md,lg,etc.. cols wrap/stack responsively. Use the non-stackingcol-xs-*class...

smmdlg等。COLS涡卷/堆栈响应。使用非堆叠col-xs-*类...

<div class="container">
  <div class="row">
    <div class="col-xs-4">.col-4</div>
    <div class="col-xs-4">.col-4</div>
    <div class="col-xs-4">.col-4</div>
  </div>
</div>

Demo: http://bootply.com/80085

演示:http: //bootply.com/80085

EDIT:Bootstrap 4, the xsno longer needs to be specified..

编辑:Bootstrap 4xs不再需要指定..

<div class="container-fluid">
  <div class="row">
    <div class="col-4">.col-4</div>
    <div class="col-4">.col-4</div>
    <div class="col-4">.col-4</div>
  </div>
</div>