简体   繁体   English

如何在引导程序中更改默认Div位置

[英]How to change default Div position in bootstrap

I am working with bootstrap and I would like to change default div positions when screen changes to small screen. 我正在使用引导程序,因此当屏幕更改为小屏幕时,我想更改默认的div位置。 Basically bootstrap div positions like this. 基本上是这样引导div位置。

在此处输入图片说明

But I want divs like this. 但是我想要这样的div。

在此处输入图片说明

I have tried pull and push method. 我尝试过推拉方法。 But it doesn't work. 但这是行不通的。

Thanks. 谢谢。

 <div class="col-sm-12"> <div class="col-sm-6"> <img src="http://loremflickr.com/320/240" /> </div> <div class="col-sm-6"> <h4> New here! </h4> <p> LoremFlickr is a service that provides free placeholder images for web and print. ... Photos come from Flickr and have a Creative Commons license. ... </p> </div> </div> <div class="col-sm-12"> <div class="col-sm-6"> <h4> New here! </h4> <p> LoremFlickr is a service that provides free placeholder images for web and print. ... Photos come from Flickr and have a Creative Commons license. ... </p> </div> <div class="col-sm-6"> <img src="http://loremflickr.com/320/240" /> </div> </div> 

Bootstrap works from small to big, check the Grid system documention. Bootstrap的工作原理从小到大,请检查Grid系统文档。 So in your case, if you want to set all the divs at full width, use the col-xs-12 class everywhere: 因此,在您的情况下,如果要将所有div设置为全角,请在各处使用col-xs-12类:

<div class="row">
    <div class="col-xs-12">
       ...image
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
       second row
    </div>
</div>
...etc

(see below for my edit. First the CSS way, then the BS4 way) (有关我的修改,请参见下文。首先是CSS方式,然后是BS4方式)

If you're using v4 beta and its flexbox grid, you can use order property in a MQ to rearrange the items of the BootStrap grid. 如果您使用的是v4 beta及其Flexbox网格,则可以在MQ中使用order属性来重新排列BootStrap网格的项目。

  • (negative including) -1 value: will display before others (from the most negative to -1 and for identical values in the order of appearance in markup (包括负数) -1值:将在其他值之前显示(从最负数到-1,并且在标记中按出现的顺序显示相同的值
  • 0 (which is the default): no rearrangement 0 (默认值):无重新排列
  • (positive including) 1 : will display after others (from 1 to the most positive and for identical values in the order of appearance in markup (包括正数) 1 :将依次显示(从1到最正数,并且在标记中的出现顺序相同,表示相同的值)

Bootply with v4 beta: https://www.bootply.com/U4Koah4OcO 使用v4 beta进行Bootply: https ://www.bootply.com/U4Koah4OcO

In markup, I rearranged items in the order you want in XS and via a MQ for small and up rearranged image to display after all other. 在标记中,我按照您想要的顺序在XS中重新排列了项目,并通过MQ进行重新排列,以便将小的和重新排列的图像显示在所有其他图像上。 If you don't want to modify your markup then you can set order: 1 on the last paragraph and override it to 0 in small and up resolutions. 如果您不想修改标记,则可以在最后一个段落中设置order: 1 ,然后在分辨率高分辨率下将其覆盖为0

EDIT: The BootStrap v4 way of reordering is using .order-N classes. 编辑: BootStrap v4的重新排序方式是使用.order-N类。 Documentation 文献资料

 @media (min-width: 576px) { .not-here-but-there { order: 1; outline: 3px dashed blue; } } 
 <!-- With BS v4 beta - <div class="container-fluid"> <div class="row"> <div class="col-sm-6"> <img src="http://loremflickr.com/320/240" /> </div> <div class="col-sm-6"> <h4> New here! </h4> <p> LoremFlickr is a service that provides free placeholder images for web and print. ... Photos come from Flickr and have a Creative Commons license. ... </p> </div> <div class="col-sm-6 not-here-but-there"> <img src="http://loremflickr.com/320/240" /> </div> <div class="col-sm-6"> <h4> New here! </h4> <p> LoremFlickr is a service that provides free placeholder images for web and print. ... Photos come from Flickr and have a Creative Commons license. ... </p> </div> </div> </div> 

@Melbin Mathai Please check following code, in which I have added bootstrap classes for different screens. @Melbin Mathai请检查以下代码,在其中为不同的屏幕添加了引导程序类。 I hope you were expecting the same. 希望您也一样。

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 "> <img src="http://loremflickr.com/320/240" /> </div> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 "> <h4> New here! </h4> <p> LoremFlickr is a service that provides free placeholder images for web and print. ... Photos come from Flickr and have a Creative Commons license. ... </p> </div> </div> <div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> <h4> New here! </h4> <p> LoremFlickr is a service that provides free placeholder images for web and print. ... Photos come from Flickr and have a Creative Commons license. ... </p> </div> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 "> <img src="http://loremflickr.com/320/240" /> </div> </div> 

Try this     
<div class="container">
       <div class="row">
         <div class="col-sm-12">
              <div class="col-sm-12 col-md-6">
                 <img src="https://loremflickr.com/320/240" />
             </div>
      <div class="col-sm-12 col-md-6">
        <h4>
          New here!
        </h4>
        <p>
          LoremFlickr is a service that provides free placeholder images for web and print. ... Photos come from Flickr and have a Creative Commons license. ...
        </p>
      </div>
      </div>
      <div class="col-sm-12">
     <div class="col-sm-12 col-md-6 col-md-push-6" >
       <img src="https://loremflickr.com/320/240" />
      </div>
      <div class="col-sm-12 col-md-6 col-md-pull-6">
        <h4>
          New here!
        </h4>
        <p>
          LoremFlickr is a service that provides free placeholder images for web and print. ... Photos come from Flickr and have a Creative Commons license. ...
        </p>
      </div>

    </div>
      </div>
    </div>

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

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