【问题标题】:Bootstrap vertical aligned without breaking the gridBootstrap 垂直对齐而不破坏网格
【发布时间】:2016-10-26 09:06:12
【问题描述】:

我一直在尝试我发现垂直对齐网格的所有不同选项。由于布局,我没有一个工作。

这是我必须做的:对于 COL-MD 和 COL-LG,布局应该是:

DIV1-IMG     DIV2-TEXT
DIV3-TEXT    DIV4-IMG

在这种情况下,DIV-TEXT 必须垂直对齐。

对于 COL-SM 及以下,布局应为:

DIV1-IMG
DIV2-TEXT
DIV4-IMG (if it is complicated, we can stick to first show DIV3-TEXT and then DIV-4-IMG)
DIV3-TEXT

问题是,如果我将 div 设置为 display:table 及其变体,网格会中断并且不会调整为 col-xs 的大小。

在这里我设置了示例,以防您看到我要完成的工作:http://www.bootply.com/nCIExg8DkM

关于如何在不破坏网格的情况下垂直对齐文本的任何想法?
谢谢!

【问题讨论】:

    标签: html css twitter-bootstrap vertical-alignment


    【解决方案1】:
    1. 使用media queries 减少您的风格的覆盖范围:@media (min-width: 992px) {}
    2. change the order of your columns 使用.col-md-push-6.col-md-pull-6 修饰符类。
    3. 简化类:
      • col-xs-12 col-lg-6 col-md-6 等于 col-md-6
      • col-lg-offset-2 col-lg-8 col-md-offset-1 col-md-10 col-xs-offset-1 col-xs-10 等于 col-lg-offset-2 col-lg-8 col-xs-offset-1 col-xs-10
    4. 使用特别有用的类:

    查看结果:http://www.bootply.com/WEf5cQlDog

    @media (min-width: 992px) {
      .vertical-middle > div {
        display: table-cell;
        float: none;
        vertical-align: middle;
      }
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    
    <div class="container">
      <div class="row">
        <div class="col-xs-offset-1 col-xs-10 col-lg-offset-2 col-lg-8">
          <div class="row vertical-middle">
            <div class="col-md-6">
              <img src="http://www.hercampus.com/sites/default/files/2013/02/27/topic-1350661050.jpg" class="center-block img-responsive">
            </div>
            <div class="col-md-6 text-center">
              <h2>Title 1</h2>                          
              <p>Text to be centered</p>
            </div>
          </div>
          <div class="row vertical-middle top-buffer">
            <div class="col-md-6 col-md-push-6">
              <img src="http://www.hercampus.com/sites/default/files/2013/02/27/topic-1350661050.jpg" class="center-block img-responsive">
            </div>
            <div class="col-md-6 col-md-pull-6 text-center">
              <h2>Title 2</h2>
              <p>Text to be centered</p>
            </div>
          </div>
        </div>
      </div>
    </div>

    【讨论】:

    • 格莱布,非常感谢。效果很好!关于列中顺序的更改,我无法使其工作。当图像位于右侧 div 时(仅适用于 col-sm),我想将其向上推,以便文本(位于左侧 DIV 上)出现在图像之后。我在这里留下了代码,但它不能正常工作:bootply.com/J3wLVUzbcc你能告诉我我做错了什么吗?
    • @Gonzalo 1) 按照它们必须站在窄屏幕上的顺序放置块。如果我理解正确,图像应该是第一个。 2)使用一对类。图像获得col-md-push-6 类。文本获得col-md-pull-6 类。
    • 那行得通,我反其道而行之。非常感谢!
    猜你喜欢
    • 2015-08-24
    • 1970-01-01
    • 2014-05-06
    • 1970-01-01
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    相关资源
    最近更新 更多