How to insert a column between two rows of another column during responsiveness in bootstrap - css

My normal layout is:
|A||C|
|B||C|
There are two columns - left and right.
'A' and 'B' are two rows of left column
'C' is right column.
When I resize, i want it to respond like:
|A|
|C|
|C|
|B|
Code:
<div class="container row">
<div class="col-sm-8">
<div class="row">
a
</div>
<div class="row">
b
</div>
</div>
<div class="col-sm-4">
c
</div>
</div>
I think I have found the solution based on Dan's
<div class="container">
<div class="row">
<div class="col-sm-8">
<div class="col-sm-12 col-xs-12" style="background-color: red">a</div>
<div class="col-sm-6 col-xs-12 visible-xs" style="background-color: blue">c</div>
<div class="col-sm-12 col-xs-12" style="background-color: orange">b</div>
</div>
<div class="col-sm-4 hidden-xs">
<div class="col-sm-12 col-xs-12" style="background-color: blue">c</div>
</div>
</div>
</div>

Based on my understanding of your needs this is how you accomplish your reordering using bootstrap the way it was intended:
<div class="container">
<div class="row">
<div class="col-sm-6 col-xs-12">a</div>
<div class="col-sm-6 col-xs-12">c</div>
<div class="col-sm-push-6 col-sm-6 col-xs-12">c</div>
<div class="col-sm-pull-6 col-sm-6 col-xs-12">b</div>
</div>
</div>
jsFiddle
Here's a link to the official bootstrap documentation on ordering.
Update based on comments:
Here's a solution using bootstrap exclusively:
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="col-sm-12 col-xs-12">a</div>
<div class="col-sm-12 col-xs-12">c</div>
<div class="col-sm-12 col-xs-12 visible-xs">c</div>
<div class="col-sm-6 col-xs-12 visible-xs">b</div>
</div>
<div class="col-sm-6 hidden-xs">
<div class="col-sm-12 col-xs-12">c</div>
<div class="col-sm-12 col-xs-12">b</div>
</div>
</div>
</div>
jsFiddle

.col-*-push-* and .col-*-pull-* are used to reorder columns for differnt screen sizes. So you would use .col-sm-pull-6 on column C2 and .col-sm-push-6 on column B. Simply adjust the amount of columns you need to push / pull to your layout.
Learn more at : getbootstrap.com/css/#grid

could also use float as a solution (if you don't feel like using push/pull)
HTML
<div class="row">
<div class="col-sm-6 col-xs-12 a">
AAA
</div>
<div class="col-sm-6 col-xs-12 c">
CCC
</div>
<div class="col-sm-6 col-xs-12 c">
CCC
</div>
<div class="col-sm-6 col-xs-12 b">
BBB
</div>
</div>
Css
.a,.b,.c{height:60px;}
.a{background:red;}
.b{background:yellow;}
.c{background:blue;float:right;}
#media screen and (max-width:767px){
.c{float:none;}
Here's a jsfiddle jsfiddle

Related

can i have a multi-height bootstrap grid layout? [duplicate]

This question already has answers here:
Make a div span two rows in a grid
(2 answers)
Closed 2 years ago.
I have a layout I am trying to achieve.
Col 1 | Col 2 | Col 3
Col 2 is "col-md-6 col-lg-6" and Col 1 and Col 3 are "col-md-3 col-lg-3" respectively
I want something like this:
However I end up with everything on one side like this:
And if I try and use pull or push classes I end up with unwanted spaces:
Here is some sample code that is close to what I have:
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
content1
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
content2
</div>
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
content3
</div>
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
content4
</div>
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
content5
</div>
</div>
Thanks in advance!
Try this way to get the first image like result
<div class="container">
<div class="row">
<div class="col-3">
<div class="bg-danger">1</div>
<br />
<div class="bg-danger">2</div>
</div>
<div class="col-6">
<div class="bg-danger">3</div>
</div>
<div class="col-3">
<div class="bg-danger">4</div>
<br />
<div class="bg-danger">5</div>
</div>
</div>
Or another way to put columns inside a column
<div class="row">
<div class="col-3">
<div class="row">
<div class="col-12">
<div class="bg-danger">1</div>
</div>
<div class="col-12">
<div class="bg-danger">1</div>
</div>
</div>
</div>
<div class="col-6">
<div class="bg-danger">3</div>
</div>
<div class="col-3">
<div class="row">
<div class="col-12">
<div class="bg-danger">1</div>
</div>
<div class="col-12">
<div class="bg-danger">1</div>
</div>
</div>
</div>
</div>
</div>
and to control height you can use
That will make all elements with the same height.
and don't put it if you want the height to be as the content of each column.
.row {
display: flex;
align-items: stretch;
}

Reordering bootstrap columns(nested)

So I have three columns in bootstrap and are the following
Mobile:
[A]
[C]
[B]
Desktop:
[A][C]
[B]
Following is my code:
<div class="container">
<div class="row">
<div class="content1 col-xs-12 col-md-6">
A
<div class="row">
<div class="content2 col-xs-12 col-md-12 hidden-xs hidden-sm">
B
</div>
</div>
</div>
<div class="content3 col-xs-12 col-md-6">
C
</div>
<div class="content2 col-xs-12 col-md-12 hidden-md hidden-lg">
B
</div>
</div>
I have achieved it using hidden classes, but is there a better way to do it using push/pull classes for example?
PS: I have a fixed height for [C], lets say 50vh.
You don't need to use nesting, push/pull or hidden classes. Use 50% width columns on larger md widths.
https://www.codeply.com/go/3APQ7tHCgS
<div class="container">
<div class="row">
<div class="content1 col-md-6">
A
</div>
<div class="content3 col-md-6">
C
</div>
<div class="content2 col-md-12">
B
</div>
</div>
</div>
Also, note that col-xs-12 is implied in Bootstrap 3 when a larger grid column is used so it's not needed in the markup.
Related: How do I change Bootstrap 3 div column order
Try this fiddle...
.content1{height:50vh !important;}
<div class="container">
<div class="content1 col-xs-12 col-md-6">
A
</div>
<div class="content3 col-xs-12 col-md-6">
C
</div>
<div class="content2 col-xs-12 col-md-12">
B
</div>
</div>
I think its working in both sizes (mobile and desktop).

Padding between columns in CSS

I would like to know if there's a better solution to solve the space problem between the two first columns in this code: https://jsfiddle.net/5vtc1Lhp/#&togetherjs=qkIyJnDkmf
I did try to place div inside div, but the width of the div decreased in the first example ( at the top). At the botton it works fine, but I had to define a padding value in px which I don't like since it's a fixed value and I don't know if this spacement should change automatically.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-8">
<div class="col-md-12">
<div class="col-md-4">
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
<div class="col-md-8">
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
</div>
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
<div class="col-md-4">
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
</div>
</div>
</div>
<hr>
Bellow is OK.
<hr>
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-8">
<div class="col-md-4 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
<div class="col-md-8" style="padding: 0 0px 0 30px;">
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
<div class="col-md-4">
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
</div>
</div>
</div>
Thank you!
Container gives gutter of 30px(15px on left and right)
If you remove the container and give it a row.It will give -15px padding on both sides. And that's what you are looking for, right?
<div class="row">
<div class="col-md-8">
<div class="row">
<div class="col-md-4">
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
<div class="col-md-8">
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
</div>
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
<div class="col-md-4">
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
<div class="col-md-12 well text-center">
...<br>...<br>...<br>...<br>...<br>...<br>...
</div>
</div>
</div>

How to create two independent columns using the twitter bootstrap grid framework

I want to create a (more or less Pinterest like) grid layout like in the below below. The two columns have different rows, but do appear side to side. How can I do this using the twitter bootstrap grid framework?
If I'm not mistaken the normal row/col behaviour would give me the layout below.
You should be able to achieve the layout by using two columns which themselves have rows:
<div class="row">
<div class="col-xs-6">
<div class="col-xs-12">1</div>
<div class="col-xs-12">2</div>
<div class="col-xs-12">
<div class="row">
<div class="col-xs-6">3</div>
<div class="col-xs-6">4</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="col-xs-12">5</div>
<div class="col-xs-12">
<div class="row">
<div class="col-xs-6">6</div>
<div class="col-xs-6">7</div>
</div>
</div>
<div class="col-xs-12">8</div>
</div>
</div>
http://jsfiddle.net/zz4ug/
Create the illusion of incongruous rows via background color or image:
<div class="container">
<div class="row">
<div class="col-xs-6 red"> </div>
<div class="col-xs-6 orange"> </div>
</div>
<div class="row">
<div class="col-xs-6 red"> </div> <--This will appear to be on row 1
<div class="col-xs-3 blue"> </div>
<div class="col-xs-3 green"> </div>
</div>
</div>
Check out this jsFiddle

Bootstrap 3: Column Ordering

I have these three columns.
In a Medium screen, It should go like: Column A (col-md-6) will be at the top, Column B (col-md-6) beside Column A,and Column C (col-md-12) underneath Column A and B.
Like so:
I'm having a problem with coming up into this kind of ordering.
Here's my current code:
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="content1 col-xs-12 col-md-6">
6-Col-[X-Small] A
</div>
<div class="content3 col-xs-12 col-md-12">
12-Col-[Medium] C
</div>
<div class="content2 col-xs-12 col-md-6">
6-Col-[X-Small] B
</div>
</div>
</div>
</div>
It looks like this at the moment:
I checked out the Bootstrap Docs and used column pushing/pulling.
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="content1 col-xs-12 col-md-6">
6-Col-[X-Small] A
</div>
<div class="content3 col-xs-12 col-md-12 col-md-push-6">
12-Col-[Medium] C
</div>
<div class="content2 col-xs-12 col-md-6 col-md-pull-12">
6-Col-[X-Small] B
</div>
</div>
</div>
</div>
But this method seems to mess up the layout.
Did I miss something in my code? It doesn't go as I intended.
You can nest your row classes within each other like so:
<div class="container">
<div class="row">
<div class="content1 col-xs-12 col-md-6">
6-Col-[X-Small] A
<div class="row">
<div class="content3 col-xs-12 col-md-12">
12-Col-[Medium] C
</div>
</div>
</div>
<div class="content2 col-xs-12 col-md-6">
6-Col-[X-Small] B
</div>
</div>
</div>
and then set a custom media query on the nested .content3 element
#media(min-width: 992px){
.content3{
width: calc(100% * 2);
}
}
The above uses the same width break point as Bootstrap's .col-md-12. At that threshold, the width of .content3 becomes twice that of it's nesting DIV.
Fiddle
<div class="container">
<div class="row">
<div class="content1 col-md-6">
6-Col-[X-Small] A
</div>
<div class="content2 col-xs-12 col-md-6">
6-Col-[X-Small] B
</div>
</div>
<div class="row">
<div class="content3 col-xs-12 ">
12-Col-[Medium] C
</div>
</div>
</div>
You'll have to duplicate some of your content(either column b or c) and add visible-xs and hidden-xs to the appropriate version of content. Initially, I didn't like the idea of duplicating the content, but then realized it made sense for optimization as I could load bigger/smaller photo depending on device.
See my previous similar question, with a great example Fiddle by #paulalexandru.
Here is the setup with your example content, and a Fiddle:
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="content1 col-md-6 purple">
6-Col-[X-Small] A
</div>
<div class="content3 col-md-12 visible-xs blue">
12-Col-[Medium] C
</div>
<div class="content2 col-md-6 red">
6-Col-[X-Small] B
</div>
<div class="content3 col-md-12 hidden-xs green">
12-Col-[X-Small] C V2
</div>
</div>
</div>
</div>
Note: The blue, red, green, purple classes are for easier visibility of what's going on in the example.
Also, if you've got content that is col-xs-12 and want it to also be col-12 at bigger screens, it will happen automatically. Don't specify col-xs-12 and col-md-12 If you do it seems to throw off the height (in this example anyways - why is a little unclear to me, but that's beside the point).
Patient: "It hurts when I do this..?" Dr: "Don't do that." :)
Also also, you'll notice a 2nd jump in layout at sm, because that's what lives between xs and md. Assuming you don't want that, you should replace col-md-* with col-sm-* in your example. Unless that's behaviour you want.

Resources