I need to realize a pretty weird layout and i'm actually using bootstrap.
I have 3 boxes: A, B and C where A.height = B.height + C.height.
On mobile, they should render in the following order:
|B|
|A|
|C|
While on desktop i need the following layout:
|A||B|
| ||C|
(Basically A is the left column while B and C are on the right)
I can't figure out how C should be positioned.
Actually i have this code, it is perfect on mobile but on desktop produces the following layout:
|A||B|
| |
|C|
Code:
<div class="container">
<div class="col-sm-12 col-md-6 col-md-push-6">B</div>
<div class="col-sm-12 col-md-6 col-md-push-6">A</div>
<div class="col-sm-12 col-md-6">C</div>
</div>
Otherwise, putting B and C in the same box works great in desktop but produces
|B|
|C|
|A|
on mobile.
Do you have any suggestion?
Following structure will fix your problem:
<div class="container">
<div class="col-xs-12 col-md-6 pull-right">B</div>
<div class="col-xs-12 col-md-6">A</div>
<div class="col-xs-12 col-md-6 pull-right">C</div>
</div>
.box-B,
.box-C {
background: green;
height: 200px;
}
.box-A {
background: blue;
height: 400px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="col-xs-12 col-md-6 pull-right box-B">B</div>
<div class="col-xs-12 col-md-6 box-A">A</div>
<div class="col-xs-12 col-md-6 box-C pull-right">C</div>
</div>
Try the C like this:
<div class="container">
<div class="col-sm-12 col-md-6 col-md-push-6">B</div>
<div class="col-sm-12 col-md-6 col-md-push-6">A</div>
<div class="col-sm-12 col-md-6 coll-md-offset-6">C</div>
</div>
OR:
<div class="container">
<div class="col-sm-12 col-md-6 col-md-push-6">B</div>
<div class="col-sm-12 col-md-6 col-md-push-6">A</div>
<div class="col-sm-12 col-md-6 pull-right">C</div>
</div>
To change their view in phones or tablets you can use the implemented classes for it for example:
<div class="col-lg-12 col-xs-6">
<p></p>
</div>
<div class="col-lg-12 col-xs-6">
<p></p>
</div>
Like this in laptops, desktop you will see full width and in phone you will see both divs aligned in one row.
You can allso use col-xs-offset-* to move the div positions but you gotta make shure that you have space.
For Example:
--- THIS IS WRONG --- Because you have only 12 cols and you are setting 2 + 2 offsets so that means you need total of 16 cols.
<div class="col-lg-12 col-xs-6 col-xs-offset-2">
<p></p>
</div>
<div class="col-lg-12 col-xs-6 col-xs-offset-2">
<p></p>
</div>
--- THE RIGHT WAY ---
<div class="col-lg-12 col-xs-4 col-xs-offset-2">
<p></p>
</div>
<div class="col-lg-12 col-xs-4 col-xs-offset-2">
<p></p>
</div>
The classes in bootstrap are:
lg - desktop
md - laptop
sm - small devices (tablets)
xs - extra small devices (phones)
together with them you can use col-**-offset-** or col-**-hidden or col-**- visible
But once again if you are going to use offset make sure you are not going above 12 cols
Hope this will help you!
using rows and pull-right you can get the effect you're looking for:
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-6 col-md-push-6 pull-right">B</div>
<div class="col-sm-12 col-md-6 col-md-push-6 pull-right">A</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-6 pull-right">C</div>
</div>
</div>
that should do the trick.
Related
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-12 order-2">1
</div>
<div class="col-lg-4 col-md-12 order-1">2
</div>
</div>
</div>
I have 2 columns which I want to order in different ways on desktop and mobile. Order-1 works fine on mobile. But it works on desktop too. Help me to change order only for mobile view in Bootstrap 4.
Bootstrap is mobile first. You will need to add a different class for larger displays.
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-12 order-2 order-sm-1">1
</div>
<div class="col-lg-4 col-md-12 order-1 order-sm-2">2
</div>
</div>
</div>
Grid breakpoints are based on minimum width media queries, meaning they apply to that one breakpoint and all those above it (e.g., .order-sm-* applies to small, medium, large, and extra large devices, but not the first xs breakpoint).
Note that you have the classes order-2 and order-1. These classes are the same as order-xs-*.
So, if you want special rules only for large displays (lg and xl), just add the classes:
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-12 order-2 order-lg-1">1
</div>
<div class="col-lg-4 col-md-12 order-1 order-lg-2">2
</div>
</div>
</div>
You only need to do this...
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-12 order-md-2">1
</div>
<div class="col-lg-4 col-md-12 order-1">2
</div>
</div>
</div>
https://www.codeply.com/go/1niA4HHVoV
I have been reading a lot of questions and answers here about swapping, rearranging and replacing divs using bootstrap, but I couldn't solve my problem.
I have two divs that contain more divs in it.
One div(A) is on the right side and another on the left(B).
In desktop and tablet view they are set one next to another AB.
When on mobile view I want A to be under B.
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-6">
A
</div>
<div class="col-md-6 col-sm-6">
B
</div>
</div>
</div>
I have tried with pull and push but it didn't work.
Any help will be appreciated. Thanks
Here is one solution that did the trick for me:
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-6 col-lg-6 col-push-6">
Content B
</div>
<div class="col-md-6 col-sm-6 col-lg-6 col-pull-6">
Content A
</div>
</div>
</div>
SEE WORKING EXAMPLE HERE
Read more on Bootstrap ordering here
You can use a trick by visible class:
<div class="row">
<div class="col-md-6 col-sm-6 visible-lg visible-md">
A (Visible-lg & md)
</div>
<div class="col-md-6 col-sm-6">
B
</div>
<div class="col-md-6 col-sm-6 visible-sm visible-xs">
A (Visible-sm & xs)
</div>
</div>
I am using Bootstrap grid as follows:
<div class="row">
<div class="col-md-6 col-sm-12"> Column A </div>
<div class="col-md-6 col-sm-12"> Column B </div>
</div>
Which obviously shows Column A on the left and Column B on the right.When move to smaller screens it will be A on top and B below.
Is there a way to keep A on the left and B on the right on larger screens, but let B be on top and A below on small screens?
Thank you.
You can use Bootstrap Push and Pull.
body,
html {
padding-top: 50px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container text-center">
<div class="row">
<div class="col-md-6 col-md-push-6">
<div class="alert alert-info">B</div>
</div>
<div class="col-md-6 col-md-pull-6">
<div class="alert alert-danger">A</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 hidden-sm hidden-xs"> Column A </div>
<div class="col-md-6 col-sm-12"> Column B </div>
<div class="col-sm-12 col-xs-12 hidden-lg hidden-md"> Column A </div>
</div>
you can add a duplicate column from A after B.
Hide the first A when the screen is sm or xs.
And hide the second A when screen is lg or md.
I have a Boostrap layout that has four centred columns when the screen is large, two columns when small, and one column when extra small. This works ok except when viewed at the small screen size when the columns do not wrap how I want them to.
On a large screen it looks like:
>zzz xxx yyy aaa
On an extra small screen it looks like:
>zzz
>xxx
>yyy
>aaa
But on a small screen it looks like:
> zzz
>xxx yyy
>aaa
I need it to look like:
zzz xxx
yyy aaa
My Boostrap code is:
<div class="row text-center">
<div class="col-xs-12 col-sm-6 col-md-2 text-center">
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">zzz</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">xxx</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">yyy</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">aaa</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2 text-center">
</div>
</div>
Any suggestions as to how I can achieve what I want?
What you have is actually:
(empty) zzz xxx yyy aaa (empty)
Your md allows for all 6 columns in a row (2 cols each), so that works fine (offsetting the first seemingly by 2 columns due to it being empty)
Your xs makes all of them 12 columns wide so this will also seemingly work as they all stretch across (with a blank column on top and below).
Your sm is working correctly but it looks as though it is not due to the extra columns you have.
Either remove these empty divs or if you really need them do this:
<div class="row text-center">
<div class="col-xs-12 col-sm-12 col-md-2 text-center">
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">zzz</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">xxx</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">yyy</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">aaa</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-2 text-center">
</div>
</div>
[EDIT - using offsets]
If you are simply looking for offsets at the md value, this should work instead of cluttering your mark-up with empty divs.
<div class="row text-center">
<div class="col-xs-12 col-sm-6 col-md-2 col-md-offset-2">
<div class="text-center">zzz</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">xxx</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">yyy</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-2">
<div class="text-center">aaa</div>
</div>
</div>
You have a blank div. Remove that and it will work as intended.
<div class="col-xs-12 col-sm-6 col-md-2 text-center"> </div>
Class col-md-* have a minimal space. If you use min-height: 0px;, it will may help you.
<div class="col-xs-12 col-sm-6 col-md-2 text-center" style="min-height: 0px;">
I'm new to Bootstrap and i have a six columns contact form, when I'm looking it on my smartphone i see the button on top, or in general i see the order in revers to what i need, this is the code:
i see samples of push,
<div class="row"> <div class="col-md-9 col-md-push-3">.col-md-9 .col-md-push-3</div> <div class="col-md-3 col-md-pull-9">.col-md-3 .col-md-pull-9</div> </div>
but how to do it with six columns?
<div class="row">
<div class="col-sm-4 col-md-4">
<div class="row">
<div class="col-sm-12 col-md-6" >div1</div>
<div class="col-sm-12 col-md-6" >div2</div>
</div>
</div>
<div class="col-sm-4 col-md-4">
<div class="row">
<div class="col-sm-12 col-md-6" >div3</div>
<div class="col-sm-12 col-md-6" >div4</div>
</div>
</div>
<div class="col-sm-4 col-md-4">
<div class="row">
<div class="col-sm-12 col-md-6" >div5</div>
<div class="col-sm-12 col-md-6" >div6</div>
</div>
</div>
how can i reverse the ordering
What you are doing is much simpler when written with right way in Bootstrap.
Try the following snippet:
<div class="container">
<div class="row">
<div class="col-md-2 col-sm-4">div1</div>
<div class="col-md-2 col-sm-4">div2</div>
<div class="col-md-2 col-sm-4">div3</div>
<div class="col-md-2 col-sm-4">div4</div>
<div class="col-md-2 col-sm-4">div5</div>
<div class="col-md-2 col-sm-4">div6</div>
</div>
</div>
When on medium size screen the divs will show in a single line, but when you go on small screen, then will stack up to show 3 divs in a row, when you go on extra small screen the divs will stack up to show only one in a row.
Try this and inform me, if you are able to achieve the right layout or not.
Updated Code:
<div class="container">
<div class="row">
<div class="col-md-2 col-sm-4 visible-lg visible-md visible-sm">div1</div>
<div class="col-md-2 col-sm-4 visible-lg visible-md visible-sm">div2</div>
<div class="col-md-2 col-sm-4 visible-lg visible-md visible-sm">div3</div>
<div class="col-md-2 col-sm-4 visible-lg visible-md visible-sm">div4</div>
<div class="col-md-2 col-sm-4 visible-lg visible-md visible-sm">div5</div>
<div class="col-md-2 col-sm-4">div6</div>
<div class="col-md-2 col-sm-4 visible-xs">div5</div>
<div class="col-md-2 col-sm-4 visible-xs">div4</div>
<div class="col-md-2 col-sm-4 visible-xs">div3</div>
<div class="col-md-2 col-sm-4 visible-xs">div2</div>
<div class="col-md-2 col-sm-4 visible-xs">div1</div>
</div>
</div>
You can't reverse the order but you can use some extra divs to achieve this functionality. Lets take extra 5 divs below 6th div and put them in reverse order. These divs will only show up on mobile screen. At the same time hide the above 5 divs at mobile screen. So now on mobile screen you are seeing divs in reverse order.
As users in comments said, please move your CSS to external .css file, that way it it easier to read and help,
Please use Plunkr or similar so people can better understand your question.
Try removing dir=rtl from outer div,
also you might want to read about Twitter Bootstrap's Helper Classes
This is a simple bootstrap grid example,
where on 'xs' screen each div will take 6 (1/2) of available space.
<div class="container">
<div class="row">
<div class="col-sm-8 col-xs-6">.col-md-1</div>
<div class="col-sm-4 col-xs-6">.col-md-2</div>
</div>
</div>
see this plunkr for example