Is it possible to do this?
I have 3 columns in a row. The first column has 2 nested row - top and bottom.
Is it possible to have the bottom row of the first column to be at the fourth position is the mobile view?
Here is my code:
http://www.bootply.com/yhhFaWRjC6
Edit:
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row" style="height:100%;">
<div class="col-md-4 col-lg-4 col-sm-12" style="background-color:#ccc;height:100%; padding:0px;">
<div class="row">
<div class="col-md-12 " style="height:180px;background-color:#d33;">one</div>
</div>
<div class="row">
<div class="col-md-12 " style="height:180px;background-color:#edd;">four</div>
</div>
</div>
<div class="col-md-4 col-lg-4 col-sm-12" style="height:360px;background-color:#e42;">two</div>
<div class="col-md-4 col-lg-4 col-sm-12" style="height:360px;background-color:#444;color:#fff;">three</div>
</div>
</div>
I want to make it the sequence to be:
- one
- two
- three
- four
In mobile
Assuming the first column to be less in height than both the second and third column I'm afraid you can only achieve this by:
Duplicating the content of the fourth column and showing/hiding it based on the grid size (e.g. xs). I'll show an example of this below.
Using JavaScript to move the content of the fourth column when the grid size changes. I have a small prototype of a jQuery plugin to facilitate this at https://github.com/ckuijjer/jquery-breakpointspy
Create your own grid system using flexbox. This might be an option if you don't have to support IE9 or lower.
I've implemented the first option below, and made some additional changes:
I've moved the inline styling into classes named .one, .two, .three and .four to make the code a little bit more clean.
I've started with the mobile layout and gave all classes col-xs-12. This makes a column take up 12 columns from the size xs onwards.
<div class="container">
<div class="row">
<div class="col-xs-12 one">one</div>
...
<div class="col-xs-12 four">four</div>
</div>
</div>
As we want to have each column take up a fourth of the container, I've added col-md-4 to each of the columns. Each column now looks like e.g. <div class="col-xs-12 col-md-4 one">. There is no need to add col-lg-4 nor col-sm-12.
Showing a column only on a specific grid size can be done by e.g. visible-xs-block. As we want the fourth column to only be visible on xs and sm I've changed the html into <div class="col-xs-12 visible-xs-block visible-sm-block four">four</div>. Notice that I've dropped the col-md-4 as there is no need for that anymore.
To put the fourth column below the first column when the screen is md or lg the first column is changed into a nested grid. I've opted not to use a second .row as having more than 12 columns will make the next column drop anyway and used .col-xs-12 as I always want a column to have a bootstrap grid class on it, regardless of the screen size. I could've used visible-md-block and visible-lg-block to make it show on md and lg only, but for fun I've used its opposite, hidden-xs and hidden-sm.
<div class="col-xs-12 col-md-4">
<div class="row">
<div class="col-xs-12 one">one</div>
<div class="col-xs-12 hidden-xs hidden-sm four">four</div>
</div>
</div>
See the entire code below:
.one {
height: 180px;
background-color: #d33;
}
.two {
height: 360px;
background-color: #e42;
}
.three {
height: 360px;
background-color: #444;
color: #fff;
}
.four {
height: 180px;
background-color: #edd;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-4">
<div class="row">
<div class="col-xs-12 one">one</div>
<div class="col-xs-12 hidden-xs hidden-sm four">four</div>
</div>
</div>
<div class="col-xs-12 col-md-4 two">two</div>
<div class="col-xs-12 col-md-4 three">three</div>
<div class="col-xs-12 visible-xs-block visible-sm-block four">four</div>
</div>
</div>
Related
this is my situation with bootstrap I put 2 blocks next to each other:
class="col-6 col-sm-6 col-md-6 col-lg-6"
At a certain point when we reach 1000px I want the boxes to be among each other like this:
this now only happens when i reach 576px,
does someone how i can accomplish this.
code:
<div class="col-sm-6">
<div class="modal-dialog modal-dialog-enable">
<div class="modal-content modal-dialog-enable" >
<div class="modal-header modal-dialog-enable">
</div>
<div class="modal-body modal-dialog-enable">
<p>
</p>
</div>
<div class="modal-footer modal-dialog-enable">
</div>
</div>
</div>
</div>
THX a lot
You can read this information:
"At a certain point when we reach 1000px I want the boxes to be among each other like this."
1000px belongs medium, and now display 2 columns (each has 50% width).
Way 1: Rewrite class name
<div class="col-6 col-sm-6 col-md-12 col-lg-6">First column</div>
<div class="col-6 col-sm-6 col-md-12 col-lg-6">Second column</div>
Way 2: Overwrite default bootstrap.min.css
#media (min-width: 992px)
.col-md-6 {
width: 100%;
}
how do I make the bootstrap grid like this?
if ≥ 576px:
if < 576px:
Thank you.
Bootstrap's col-xs-$ has the lowest max-width of 768px. I think you will have to add another class to your columns and then specify your CSS rule to that class
For example :
<div class="col-xs-4 smaller-div-class">
Col 1
</div>
<div class="col-xs-4 smaller-div-class">
Col 2
</div>
<div class="col-xs-4 smaller-div-class">
Col 3
</div>
and so on... and add the style in smaller-div-class
#media screen and (max-size<576px){
.smaller-div-class{
width: 100% !important;
}
}
Bootstrap rows each contain 12 columns, and each column should be confined to a row.
Considering you want three columns, you should specify that each has a width of 4 columns, as 12 / 3 = 4. This is done by using col-sm-4 as a class name.
The col-sm- prefix for columns is based on the 'Small' screen sizes, and actually defaults to the exact width you want of 576px:
This can be seen in the following example:
.one {
background: red;
}
.two {
background: blue;
}
.three {
background: green;
}
.col-sm-4 {
height: 50px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="row">
<div class="col-sm-4 one"></div>
<div class="col-sm-4 two"></div>
<div class="col-sm-4 three"></div>
</div>
Hope this helps! :)
<div class="container">
<div class="row">
<div class="col-sm-4 col-12">
<h2>col1</h2>
</div>
<div class="col-sm-4 col-12">
<h2>col2</h2>
</div>
<div class="col-sm-4 col-12">
<h2>col3</h2>
</div>
</div>
<div class="row">
<div class="col-sm-4 col-12">
<h2>col4</h2>
</div>
<div class="col-sm-4 col-12">
<h2>col5</h2>
</div>
<div class="col-sm-4 col-12">
<h2>col6</h2>
</div>
</div>
</div>
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
On my page I have a calendar, I want it to be responsive, so that On Large screens it will look like this:
[Jan] [Feb] [Mar]
[Apr] [May] [June]
[July] [Aug] [Sept]
[Oct] [Nov] [Dec]
When resizing to middle this:
[Jan] [Feb]
[Mar] [Apr]
[May] [June]
[July] [Aug]
[Sept] [Oct]
[Nov] [Dec]
The problem is that I group them by 3 elements to one row (large screens view).
(I assigned these classes to my "months": class="col-lg-4 col-md-6")
So when I change screen size to middle it is still grouped in rows and looks so:
[Jan] [Feb]
[Mar]
[Apr] [May]
[June]
[July] [Aug]
[Sept]
[Oct] [Nov]
[Dec]
Is there any way to solve this?
you can just use one .row and use .clearfix visible-lg-block for large screens at each 3nth item. See Bootstrap Docs about Responsive Columns Resets
[class^="col-"] {
border: solid red;
height: 50px;
text-align: center
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-6 col-lg-3">Jan</div>
<div class="col-md-6 col-lg-3">Feb</div>
<div class="col-md-6 col-lg-3">Mar</div>
<div class="clearfix visible-lg-block"></div>
<div class="col-md-6 col-lg-3">Apr</div>
<div class="col-md-6 col-lg-3">May</div>
<div class="col-md-6 col-lg-3">Jun</div>
<div class="clearfix visible-lg-block"></div>
<div class="col-md-6 col-lg-3">Jul</div>
<div class="col-md-6 col-lg-3">Aug</div>
<div class="col-md-6 col-lg-3">Sep</div>
<div class="clearfix visible-lg-block"></div>
<div class="col-md-6 col-lg-3">Oct</div>
<div class="col-md-6 col-lg-3">Nov</div>
<div class="col-md-6 col-lg-3">Dez</div>
</div>
</div>
I cannot center my five two columns inside of a ten column inside of a twelve column. http://jsfiddle.net/p8znkgv2/. I have tried the following "solutions" without any luck:
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-1"> </div>
<div class="col-sm-10 col-centered">
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
.col-centered{ margin: auto; float: none; }
Make the container a table and each column a table cell item ( failed )
Make the container (10 column) float none with an auto margin. ( failed on large displays )
So how can I center each two column inside the ten column with the ten column centered inside the twelve column?
So how can I center each two column inside the ten column with the ten column centered inside the twelve column?
By using .col-sm-offset-* class. Examples can be found here. http://getbootstrap.com/css/#grid-offsetting. Here's a fiddle as well. http://jsfiddle.net/yongchuc/m12cysv1/
Something like this? http://jsfiddle.net/p8znkgv2/2/
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-10 col-sm-offset-1">
<div class="col-sm-2 col-sm-offset-1">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
</div>
A lot of problems with your structure.
One is you create child div elements with those grid classes e.g. col-sm-* without adding and element with .row class first.
Html should be:
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-1"> </div>
<div class="col-sm-10 col-centered">
<div class="row">
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
<div class="col-sm-2">Coontent</div>
</div>
</div>
<div class="col-sm-1"> </div>
</div>
</div>
</div>
</div>
And regarding to center those 5 cols, since there's no specific class for 5 cols since it's a 12 grid system, add a custom style for those elements.
e.g.
.col-centered .row .col-sm-2 {
width: 20%;
}
Fiddle