简体   繁体   English

如何在响应中更改div的位置?

[英]How to change the location of div in responsive?

I have three divs as described in the image...i want to change the location of divs as they go responsive... 如图所示,我有三个div ...我想在div响应时更改div的位置...

Is it possible to do so? 有可能这样做吗? and how? 如何?

在此处输入图片说明

 <div class="container-fluid">
       <div class="row">
           <div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center "><h3 class="border">Div-1</h3></div>
           <div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center "><h3 class="border">Div-2</h3></div>
           <div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center "><h3 class="border">Div-3</h3></div>
       </div>
   </div>
<div class="container-fluid">
       <div class="row">
           <div class="first col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center "><h3 class="border">Div-1</h3></div>
           <div class="second col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center "><h3 class="border">Div-2</h3></div>
           <div class="third col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center "><h3 class="border">Div-3</h3></div>
       </div>
   </div>



    @media only screen and (max-width:990px) and (min-width:320px){
         .first, .third{
           float:left;
           width:48%; 
        }
        .second {
          width:100%;
          float:right;
           display:block;
          clear:both;
        }
       }

By using the Bootstrap defaults you would like to push and pull columns by simply adding some additional classes to them. 通过使用Bootstrap缺省值,您希望通过向其添加一些附加类来推入和拉出列。

<div class="container-fluid">
   <div class="row">
       <div class="col-sm-4 col-xs-6 text-center"><h3 class="border">Div-1</h3></div>
       <div class="col-sm-4 col-xs-6 col-sm-push-4 text-center"><h3 class="border">Div-3</h3></div>
       <div class="col-sm-4 col-xs-12 col-sm-pull-4 text-center"><h3 class="border">Div-2</h3></div>
   </div>

The point is to move the 3rd col to swap places with the 2nd col , since the 2nd will be at the bottom when it goes down to mobile. 关键是要移动第三个列第二个列交换位置,因为第二个列在移动时将位于底部。 Using .col-sm-pull and .col-sm-push will grant you the ability to move columns around easily without breaking anything with unnecessary float styling or anything else. 使用.col-sm-pull.col-sm-push将使您能够轻松移动列,而不会因不必要的浮点样式或其他任何东西而破坏任何内容。

Refer to Bootstrap's official guide to column ordering . 请参考Bootstrap的官方列排序指南

This works, 这样有效

 <div class="container-fluid">
       <div class="row">
           <div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center "><h3 class="border">Div-1</h3></div>
           <div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center "><h3 class="border">Div-2</h3></div>
           <div class="col-xs-12 col-sm-12 col-md-12 col-lg-4 text-center "><h3 class="border">Div-3</h3></div>
       </div>
   </div>

You could use http://www.w3schools.com/cssref/sel_nth-child.asp if your element hasn´t any unique id or class. 如果您的元素没有任何唯一的ID或类,则可以使用http://www.w3schools.com/cssref/sel_nth-child.asp and

float: right;

As long as 只要

@media only screen and (max-width: 990px) and (min-width:320px)
<div class="container-fluid">
  <div class="row">
           <div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center">
            <h3 class="border">Div-1</h3>
           </div>
           <div class="hidden-sm hidden-xs col-md-4 col-lg-4 text-center">
            <h3 class="border">Div-2</h3>
           </div>
           <div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 text-center">
            <h3 class="border">Div-3</h3>
           </div>
           <div class="hidden-lg hidden-md col-xs-12 col-sm-12 visible-sm-block visible-xs-block text-center">
            <h3 class="border">Div-2</h3>
           </div>
  </div>
</div>

http://getbootstrap.com/css/#responsive-utilities http://getbootstrap.com/css/#sensitive-utilities

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM