在移动设备上堆叠Bootstrap列

时间:2017-05-22 14:39:33

标签: css twitter-bootstrap

我试图让col-md-6在移动设备上的col-md-4下面堆叠,但是无法让它工作。任何建议如何实现这一点都会很棒。

<footer>

<div class="container">
  <div class="row">
    <div class="col-md-6 col-md-offset-1 col-xs-12">
      <?php
          wp_nav_menu( array(
              'menu'              => 'footer',
              'theme_location'    => 'footer',
              'depth'             => 1,
              'container'         => 'div',
              'container_id'      => 'footer-nav',
              'menu_class'        => 'nav navbar-nav',
              'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
              'walker'            => new wp_bootstrap_navwalker())
          );
      ?>
    </div>
    <div class="col-md-4 col-xs-12 copyright-text">
      <p>Copyright © <?php echo date("Y"); ?> Elliott Davidson. All Rights Reserved.</p>
    </div>
  </div>
</div>

4 个答案:

答案 0 :(得分:2)

您可以使用order来查看使用flexbox属性。查看文档here

你要做的是这样的事情:

<div class="container">
  <div class="row flex">
    <div class="col-md-6 col-md-offset-1 col-xs-12 first">Div 1</div>
    <div class="col-md-4 col-xs-12 copyright-text second">Div2</div>
  </div>
</div>


/* Make sure to use all the proper prefixers */
/* Allow this to be up to mobile of 767px */
@media all and ( max-width: 767px ) {
    .flex { display: flex; }
    .first { order: 2; }
    .second { order: 1; }
}

Take a look at this codepen将为您提供解决方案。

答案 1 :(得分:0)

切换列的顺序(首先是移动设备),然后使用Bootstrap's column ordering

<div class="row">
    <div class="col-md-4 col-md-push-6 col-md-offset-1 col-xs-12 copyright-text">
      <p>Copyright © <?php echo date("Y"); ?> Elliott Davidson. All Rights Reserved.</p>
    </div>
    <div class="col-md-6 col-md-pull-4 col-xs-12">
      <?php
          wp_nav_menu( array(
              'menu'              => 'footer',
              'theme_location'    => 'footer',
              'depth'             => 1,
              'container'         => 'div',
              'container_id'      => 'footer-nav',
              'menu_class'        => 'nav navbar-nav',
              'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
              'walker'            => new wp_bootstrap_navwalker())
          );
      ?>
    </div>    
</div>

Bootply example

答案 2 :(得分:0)

你可以用弹性盒子做到这一点。添加一个  像这样的课程

<div class="row flexible"></div>

的CSS

@media (max-width:480px){
.flexible{
display:flex;
}
.flexible div:nth-child(1){
order:1;
}
.flexible div:nth-child(2){
order:2;
}
}

答案 3 :(得分:0)

我设法通过在col-md-6中添加一个类并向右浮动来找到解决方案。

<div class="container">
  <div class="row">
    <div class="col-md-6 col-md-offset-1 col-xs-12 footer-nav">
      <?php
          wp_nav_menu( array(
              'menu'              => 'footer',
              'theme_location'    => 'footer',
              'depth'             => 1,
              'container'         => 'div',
              'container_id'      => 'footer-nav',
              'menu_class'        => 'nav navbar-nav',
              'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
              'walker'            => new wp_bootstrap_navwalker())
          );
      ?>
    </div>
    <div class="col-md-4 col-xs-12 copyright-text">
      <p>Copyright © <?php echo date("Y"); ?> Elliott Davidson. All Rights Reserved.</p>
    </div>
  </div>
</div>

.footer-nav
  float: right