Reorder columns in small devices Bootstrap 4 - grid

Unfortunately Bootstrap in Beta version drops push-* and pull-*classes, so I don't have idea how to reorder columns in xs and sm devices from:
[column_1] [column_2] [column_3]
to:
[column_1][column_3]
[column_2]
Any ideas?

There are new Reordering helper classes.
Place the divs in HTML as you want them to appear in mobile:
<div class="container">
<div class="row">
<div class="col-6 col-md-4">
[column_1]
</div>
<div class="col-6 col-md-4 order-md-12">
[column_3]
</div>
<div class="col-6 col-md-4 order-md-1">
[column_2]
</div>
</div>
</div>
[column_1] will stay first and unordered. Reorder [column_3] with .order-md-12(will be last for md-size and up) and [column_2] .order-md-1(will be first for md-size and up)
Check jsfiddle

Related

use multiple responsive layouts with bootstrap 4

if we use bootstrap 3, we can write
<div class="row">
<div class="col-lg-6 col-md-6 col-xs-12">
</div>
<div>
but how to do the same in bootstrap 4? I tried with <div class="col-6 col-12"> but it only works as col-lg-12 (full width). I need to use same div with different classes like in BS3, in BS4. how can I do that?
Your example in BS3:
<div class="row">
<div class="col-lg-6 col-md-6 col-xs-12">
</div>
<div>
BS4 version:
<div class="row">
<div class="col-md-6">
</div>
<div>
In the above code below medium devices, it will be full width (12 cols) as that's the default.
In medium-sized devices and above it will be 6 cols wide.
You can use col-12 col-md-6 as your classes.

Arrange tabs in specific order for specific device size

https://codepen.io/TheNoviceProgrammer/pen/JJzvQq
For the desktop and iPad I want the div to display it as
|1||2| Which it is displaying.
but on sm(small) and xs(extra small) mobile device I want it to display it as
|2|
|1|
I have tried bootstrap's push and pull for xs and sm but it's not working. Whereas using push(col-md-push-xx) and (col-md-push-xx)pull for xs and sm the layout of iPad and Desktop changes to |2|1| while mobile display remains the same as
|1|
|2|
I think I may have used the classes in div in a wrong way, If someone can help me out it would be much appreciated. Thanks.
My HTML
<div class="container-fluid">
<div class="row">
<div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2 col-xs-12 col-xs-offset-0 col-sm-12 col-sm-offset-0 col-sm-offset-right-0 col-xs-offset-right-0">
<div class="row">
<div class=" col-sm-12 col-sm-offset-0 col-xs-12 col-xs-offset-0 col-md-6 col-lg-4 col-lg-offset-2">
<div>Labels & a bootstrap well</div>
</div>
<div class=" col-sm-12 col-sm-offset-0 col-xs-12 col-xs-offset-0 col-md-6 col-lg-4 col-lg-offset-0 col-lg-offset-right-2">
<div>Labels & a Table Gridview</div>
</div>
</div>
</div>
<div class="col-md-1 col-lg-2"></div>
</div>
</div>
After using col-md-push and pull it overlaps as below for tablet and desktops:
[![enter image description here][5]][5]
While in mobile device its still showing same as the mobile screenshot above.
Demo Pen
Yep your instincts are correct that push and pull are the way to go. They should be: col-md-push-6 and col-md-pull-6 for Bootstrap 3. Here's a link to a pen that will help you. Also remember that the class sizing is inherent, you can call col-xs-12 and the small break point will inherit the 12 column width as well.
HTML:
<div class="container-fluid">
<div class="row">
<div class="well col-xs-12 col-md-6 col-md-push-6">Labels & a bootstrap well</div>
<div class="grid col-xs-12 col-md-6 col-md-pull-6">Labels & a Table Gridview</div>
</div><!-- row -->
</div><!-- container-fluid -->

33% Width for all device using Bootstrap for Responsive

I want take 1/3 width of a single row for all device.
Is there any other option to do instead of this code....
<div class="row">
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-4"></div>
<div class="col-md-8 col-lg-8 col-sm-8 col-xs-8"></div>
</div>
Since Bootstrap is defined mobile first, you should be able to just define the xs size, like so:
<div class="row">
<div class="col-xs-4"></div>
<div class="col-xs-8"></div>
</div>
use col-xs-4 it can act md-4 and lg-4 on larger devices.
you cannot use md-8 there is only 12 grids.

Order columns through Bootstrap4

I have 3 columns which I want to order in different ways on desktop and mobile.
Currently, my grid looks like this:
<div class="row">
<div class="col-xs-3 col-md-6">
1
</div>
<div class="col-xs-3 col-md-6">
2
</div>
<div class="col-xs-6 col-md-12">
3
</div>
</div>
In the mobile view I want to have the following output:
1-3-2
Unfortunately I don't get how to solve this with the .col-md-push-* and .col-md-pull-* classes in Bootstrap 4.
2021 - Bootstrap 5
The responsive ordering classes are now order-first, order-last and order-0 - order-5
Demo
2018 - Bootstrap 4
The responsive ordering classes are now order-first, order-last and order-0 - order-12
The Bootstrap 4 **push** **pull** classes are now `push-{viewport}-{units}` and `pull-{viewport}-{units}` and the `xs-` infix has been removed. To get the desired 1-3-2 layout on mobile/xs would be: [Bootstrap 4 push pull demo](http://www.codeply.com/go/OmrcmepbUp) (This only works pre 4.0 beta)
Bootstrap 4.1+
Since Bootstrap 4 is flexbox, it's easy to change the order of columns. The cols can be ordered from order-1 to order-12, responsively such as order-md-12 order-2 (last on md, 2nd on xs) relative to the parent .row.
<div class="container">
<div class="row">
<div class="col-3 col-md-6">
<div class="card card-body">1</div>
</div>
<div class="col-6 col-md-12 order-2 order-md-12">
<div class="card card-body">3</div>
</div>
<div class="col-3 col-md-6 order-3">
<div class="card card-body">2</div>
</div>
</div>
</div>
Demo: Change order using order-* classes
Desktop (larger screens):
Mobile (smaller screens):
It's also possible to change column order using the flexbox direction utils...
<div class="container">
<div class="row flex-column-reverse flex-md-row">
<div class="col-md-8">
2
</div>
<div class="col-md-4">
1st on mobile
</div>
</div>
</div>
Demo: Bootstrap 4.1 Change Order with Flexbox Direction
Older version demos
demo - alpha 6
demo - beta (3)
See more Bootstrap 4.1+ ordering demos
Related
Column ordering in Bootstrap 4 with push/pull and col-md-12
Bootstrap 4 change order of columns
A-C-B A-B-C
This can also be achieved with the CSS "Order" property and a media query.
Something like this:
#media only screen and (max-width: 768px) {
#first {
order: 2;
}
#second {
order: 4;
}
#third {
order: 1;
}
#fourth {
order: 3;
}
}
CodePen Link: https://codepen.io/preston206/pen/EwrXqm
even this will work:
<div class="container">
<div class="row">
<div class="col-4 col-sm-4 col-md-6 order-1">
1
</div>
<div class="col-4 col-sm-4 col-md-6 order-3">
2
</div>
<div class="col-4 col-sm-4 col-md-12 order-2">
3
</div>
</div>
</div>
I'm using Bootstrap 3, so i don't know if there is an easier way to do it Bootstrap 4 but this css should work for you:
.pull-right-xs {
float: right;
}
#media (min-width: 768px) {
.pull-right-xs {
float: left;
}
}
...and add class to second column:
<div class="row">
<div class="col-xs-3 col-md-6">
1
</div>
<div class="col-xs-3 col-md-6 pull-right-xs">
2
</div>
<div class="col-xs-6 col-md-12">
3
</div>
</div>
EDIT:
Ohh... it looks like what i was writen above is exacly a .pull-xs-right class in Bootstrap 4 :X Just add it to second column and it should work perfectly.
Since column-ordering doesn't work in Bootstrap 4 beta as described in the code provided in the revisited answer above, you would need to use the following (as indicated in the codeply 4 Flexbox order demo - alpha/beta links that were provided in the answer).
<div class="container">
<div class="row">
<div class="col-3 col-md-6">
<div class="card card-block">1</div>
</div>
<div class="col-6 col-md-12 flex-md-last">
<div class="card card-block">3</div>
</div>
<div class="col-3 col-md-6 ">
<div class="card card-block">2</div>
</div>
</div>
Note however that the "Flexbox order demo - beta" goes to an alpha codebase, and changing the codebase to Beta (and running it) results in the divs incorrectly displaying in a single column -- but that looks like a codeply issue since cutting and pasting the code out of codeply works as described.
You can do two different container one with mobile order and hide on desktop screen, another with desktop order and hide on mobile screen

Mixing different types of columns in bootstrap

Can I mix different columns (col-xs-, col-sm- etc) in my layout?
For example, I have:
<div class="col-xs-12">
...
</div>
<div class="col-xs-12">
...
</div>
<div class="col-xs-6">
...
</div>
<div class="col-xs-6">
...
</div>
and more many col-xs columns.
But now for example, I want to change first column from full width to half in tablets and monitors, so I added "col-sm-6 col-sm-offset-3" and remove "col-xs-12" because "col-sm-6" means "col-xs-12":
<div class="col-sm-6 col-sm-offset-3">
...
</div>
<div class="col-xs-12">
...
</div>
<div class="col-xs-6">
...
</div>
<div class="col-xs-6">
...
</div>
And it works, but this is correct with bootstrap grid system and standards?
Or Maybe I have to add "col-sm-*" to others? :
<div class="col-sm-6 col-sm-offset-3">
...
</div>
<div class="col-xs-12 col-sm-12">
...
</div>
<div class="col-xs-6 col-sm-6">
...
</div>
<div class="col-xs-6 col-sm-6">
...
</div>
Or maybe I have to keep "col-xs-12"?
<div class="col-xs-12 col-sm-6 col-sm-offset-3">
...
</div>
<div class="col-xs-12">
...
</div>
<div class="col-xs-6">
...
</div>
<div class="col-xs-6">
...
</div>
Or maybe I have to keep "col-xs-12" and add "col-sm-*" to others to have identical types in all divs?
<div class="col-xs-12 col-sm-6 col-sm-offset-3">
...
</div>
<div class="col-xs-12 col-sm-12">
...
</div>
<div class="col-xs-6 col-sm-6">
...
</div>
<div class="col-xs-6 col-sm-6">
...
</div>
Which versions is correct? How do I properly mix different types of columns?
Bigger sizes override smaller sizes (e.g. col-sm will override col-xs unless the screen is smaller than col-sm). Personally I always add a col-xs and I only add the bigger sizes when I need them.
Example:
<!-- full width on phones and half on anything bigger -->
<div class="col-xs-12 col-sm-6">
...
</div>
This information is all found in Bootstrap's Documentation. It is perfectly fine to add multiple col-*-* classes to a <div> element:
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
...
</div>
Is a perfectly viable class structure, that renders different column sizes depending on the current size of the viewport. If xs, it would be a full-width column. Small is half, medium is a 3rd and large is a 4th (based on a 12 column layout.)
If you need more information, take a look here:
Bootstrap Grid System
All the other answers explain what overrides what, but to answer your question about what you have to have, the default is 100% width. So if you only specify:
<div class="col-sm-6">
...
</div>
then when you get smaller than 768px it will go from 50% (6 columns) to 100 (12 columns)
Column sizing will default with the smallest size first (xs) with subsequent classes overriding the original size.
For example:
<div class="col-xs-12"></div>
Will appear as with 100% width on all browsers.
The following will appear as 100% on mobile browsers and 50% on tablets and up.
<div class="col-xs-12 col-sm-6"></div>

Resources