Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,


Here i am showing 5 columns in bootstrap in large screen.

box 1 - box 2 - box 3 - box 4 - box 5


But as per requirement i want to reorder the columns in mobile device like this.

box 1 - box 4 -

box 2 - box 3 -

box 5 -

How to achieve it?

@media (min-width: 980px) 
{
	
.col_5 { width:20%; position:relative; float:left }
	  
}


XML
<div>

<div class="col_5 col-xs-6"> box 1 </div>

<div class="col_5 col-xs-6">box 2</div>

<div class="col_5 col-xs-6">box 3 </div>

<div class="col_5 col-xs-6">box 4</div>

<div class="col_5">box 5</div>


</div>
Posted
Comments
Richard Deeming 24-Aug-15 9:34am    
I'm not aware of anything in Bootstrap to do this.

What browsers do you need to support? If you can drop IE10 and earlier, Flexbox[^] should support this.
aspdotnetkhan 24-Aug-15 10:24am    
https://www.google.ae/?gfe_rd=cr&ei=ttvaVY_RJKys8weH56ToCQ&gws_rd=ssl#start=10&q=Bootstrap+Column+reordering

The classes are used along with the Bootstrap grid classes of .col-xs-#, .col-sm-#, .col-md-#, and .col-lg-#.

The push and pull classes applied to the Bootstrap grid are .col-xs-push-# or .col-xs-pull-#. That also works with sm, md, and lg.

The push class will move columns to the right while the pull class will move columns to the left.

Please refer this for more idea:
https://scotch.io/tutorials/reorder-css-columns-using-bootstrap[^]
Codepen Demo[^]

-KR
 
Share this answer
 
I would try applying floats to the divs within the media query, this ill require each div to have an id. By applying the float to the class as you suggest in your question you will float all of your div to the left.

CSS
@media (min-width: 980px) 
{

.col_5 {
         width: 20%;
         position: relative;
}
	
#box1 {
         float: left;
}

#box2 {
         float: right;
}

#box3 {
         float: left;
}

#box4 {
         float: right;
}

#box5 {
         float: left;
}
	  
}


Then apply these id's to the boxes as follows:

HTML
<div>
 
<div id="box1" class="col_5 col-xs-6">box 1 </div>
 
<div id="box2" class="col_5 col-xs-6">box 2</div>
 
<div id="box3" class="col_5 col-xs-6">box 3 </div>
 
<div id="box4" class="col_5 col-xs-6">box 4</div>
 
<div id="box5" class="col_5">box 5</div>
 

</div>


I hope that this helps!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900