how to change div align in mobile version - html

I have 3 div in my html. div1, div2,div3. Now in mobile version I want to change the alignment of those div. I have given in below images.
HTML Code
<div class="row">
<div class="col-md-12">
Div1
</div>
<div class="col-md-9" style="float:right;">
Div3
</div>
<div class="col-md-3" style="float:left;">
Div2
/div>
</div>
But didn't solved.
How to do that?
Anybody help please ?

Looks like you are using bootstrap. If you re using Bootstrap 4 you can use the ordering feature to easily achieve this.
<div class="row">
<div class="col-md-12 order-md-1 order-sm-1">
Div1
</div>
<div class="col-md-3 order-md-2 order-sm-3">
Div2
</div>
<div class="col-md-9 order-md-3 order-sm-2">
Div3
</div>
</div>
Fiddle
EDIT
Since you are using bootstrap 3, reordering col-12 are not possible (e.g. col- * -push / col- * -pull). As alternative you can use flex-box or grid to achieve this easily. See example below.
<div class="row reordered">
<div class="col-md-12">
Div1
</div>
<div class="col-md-3">
Div2
</div>
<div class="col-md-9">
Div3
</div>
</div>
CSS - Reordered using grid
#media screen and (max-width: 992px) { //992 is the breakpoint of col-md
.reordered {
display: grid;
}
.col-md-3 {
order: 2;
}
.col-md-9 {
order: 1;
}
}
Fiddle

<div class="row">
<div class="col-md-12 col-12">
Div1
</div>
<div class="col-md-12 col-12">
<div class="row flex-row-reverse flex-column-reverse">
<div class="col-md-3 col-12">
Div2
</div>
<div class="col-md-9 col-12">
Div3
</div>
</div>
</div>
</div>

If I understand correctly, you're using the Bootstrap framework in which case you can use the "responsive utility classes" which are part of the framework's grid system to achieve what you require. To control the ordering of elements on the mobile version, you will also need to add some additional CSS.
The following changes to your HTML, along with the added CSS of .order-row etc, should achieve this for you:
#media (max-width: 768px) {
.order-row {
display: flex;
flex-direction: column;
}
.order-0 {
order: 0;
}
.order-1 {
order: 1;
}
}
<link href="https://cdn.usebootstrap.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12">
Div1
</div>
</div>
<div class="row order-row">
<div class="col-md-3 col-sm-12 order-1">
Div2
</div>
<div class="col-md-9 col-sm-12 order-0">
Div3
</div>
</div>
</div>
For more information on how to use bootstraps responsive grid classes, see this documentation

Div1
Div2
Div3

if you use bootstrap 4, you can use order
<div class="row">
<div class="col-md-12">
Div1
</div>
<div class="col-md-9 order-md-0 order-1">
Div2
</div>
<div class="col-md-3 order-md-1 order-0">
Div3
/div>
</div>
Explanation
the Div2 will show on the left on viewport md and bigger, and it will shown under Div3 if the viewport is smaller than md

Related

Bootstrap columns overlapping on small screens

I have 2 columns and on the left and the right side, When I open the web page on a small or xs screen the two columns overlap. I would like for the other column to go below the other.
<div class="container">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-9 area-style"></div>
</div>
</div>
CSS:
.area-style {
border: 1px solid #ccc;
padding-top: 2em;
background: #fafafa;
height: 500px;
}
Please check if you have given floats to the elements inside any of the "col-md-3" or "col-md-9" divs. The Overlapping 99% occurs If the floats are not cleared.
If you are using Bootstrap4 try this.
<div class="container">
<div class="row">
<div class="col-12 col-md-3"></div>
<div class="col-12 col-md-9 area-style"></div>
</div>
</div>
Try this.
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-3"></div>
<div class="col-xs-12 col-md-9 area-style"></div>
</div>
</div>
Please tell me if this helps you.

Why isn't BootStrap column offset working?

I am trying to build a website with flash-cards to help learn the Hebrew alphabet. My Card partial view looks like this:
#model FlashCards.MultipleChoice.ViewModels.CardViewModel
<div class="index-card">
<div class="row">
<div class="col-md-offset-5"></div>
<div class="col-md-2 text-center">
#Model.Numeric
</div>
</div>
<div class="row">
<div class="col-md-offset-2"></div>
<div class="col-md-8 text-center card-symbol">
#Html.Raw(Model.UnicodeEscape)
</div>
</div>
<div class="row">
<div class="col-md-offset-2"></div>
<div class="col-md-8 text-center">
#Model.Name
</div>
</div>
</div>
Now the col-md-offset works on all but the first row, causing the card to render as in the below image:
Now why isn't the 1 in the image offset like the glyph and the name for the letter Aleph?
My CSS file for these cards only contains the following so far:
.index-card {
height: 150px;
}
.index-card .card-symbol {
font-size: large
}
I believe you're using the offset classes wrong; do not apply them to empty divs.
Your text is centered. Second and third rows have widths of 8 columns. It looks like the offset is working but it really isn't. The first row is only 2 columns wide. None of your offset divs are having any effect on the layout.
You need to do something like this, at the very least:
<div class="index-card">
<div class="row">
<div class="col-md-offset-5 col-md-2 text-center">
#Model.Numeric
</div>
</div>
<div class="row">
<div class="col-md-offset-2 col-md-8 text-center card-symbol">
#Html.Raw(Model.UnicodeEscape)
</div>
</div>
<div class="row">
<div class="col-md-offset-2 col-md-8 text-center">
#Model.Name
</div>
</div>
</div>

Right column on top in Bootstrap on mobile platform

I'm trying to get the right div to be on top when viewed on a mobile device using Bootstrap, as explained and answered in this thread, meaning I want my desktop layout to look as follows:
A | B
And my mobile layout as follows:
B
A
However, the proposed following solution isn't working for me:
<div class="row">
<div class="col-md-6 col-md-push-6">B</div>
<div class="col-md-6 col-md-pull-6">A</div>
</div>
My code looks as follows:
<section id="kalender" class="kalender-section content-section text-center">
<div class="container">
<div class="row">
<div class="col-lg-4 col-lg-push-8 mx-auto">
B
</div>
<div class="col-lg-8 col-lg-push-4 mx-auto">
A
</div>
</div>
</div>
</section>
But B is still shown on the left on a desktop view.
Any ideas on what I'm doing wrong, and how to fix this? Thank you in advance.
You are using col-lg-push on both div. Use col-lg-pull-4 on your second div "A"
So your new code is:
<section id="kalender" class="kalender-section content-section text-center">
<div class="container">
<div class="row">
<div class="col-lg-4 col-lg-push-8 mx-auto">
B
</div>
<div class="col-lg-8 col-lg-pull-4 mx-auto">
A
</div>
</div>
</div>
</section>
Working JSFiddle: https://jsfiddle.net/v5a7ommf/1/
Follow below code:
https://codepen.io/hardiksolanki/pen/GOKGOx
Desktop view: A | B
Mobile view:
B
A
This can also possible with out boo-trap.
.desktop-left{
background: red;
float: right;
}
.desktop-right{
background: green;
float: left;
}
#media only screen and (max-width:980px) {
.desktop-right, .desktop-left{
float: none;
}
}

Bootstrap vertical aligned without breaking the grid

I been trying all the different options that I found to vertically align a grid. Because of the layout that I have none of them worked.
This is what I have to do: for COL-MD and COL-LG the layout should be:
DIV1-IMG DIV2-TEXT
DIV3-TEXT DIV4-IMG
In this case the DIV-TEXT has to be vertically aligned.
For COL-SM and under, the layout should be:
DIV1-IMG
DIV2-TEXT
DIV4-IMG (if it is complicated, we can stick to first show DIV3-TEXT and then DIV-4-IMG)
DIV3-TEXT
The problem is that if I set the div to display:table and its variants, the grid breaks and it doesn't resize to col-xs.
Here I set up the example in case you can see what I am trying to accomplish: http://www.bootply.com/nCIExg8DkM
Any ideas on how one can align the text vertically without breaking the grid?
Thanks!
Use media queries to reduce the coverage area of your style: #media (min-width: 992px) {}.
Use .col-md-push-6 and .col-md-pull-6 modifier classes to change the order of your columns.
Simplify classes:
col-xs-12 col-lg-6 col-md-6 is equal to col-md-6.
col-lg-offset-2 col-lg-8 col-md-offset-1 col-md-10 col-xs-offset-1 col-xs-10 is equal to col-lg-offset-2 col-lg-8 col-xs-offset-1 col-xs-10.
Use special helpful classes:
The .img-responsive class scales the image nicely to the parent element.
The .center-block class aligns the block via margin.
Check the result: http://www.bootply.com/WEf5cQlDog
#media (min-width: 992px) {
.vertical-middle > div {
display: table-cell;
float: none;
vertical-align: middle;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-xs-offset-1 col-xs-10 col-lg-offset-2 col-lg-8">
<div class="row vertical-middle">
<div class="col-md-6">
<img src="http://www.hercampus.com/sites/default/files/2013/02/27/topic-1350661050.jpg" class="center-block img-responsive">
</div>
<div class="col-md-6 text-center">
<h2>Title 1</h2>
<p>Text to be centered</p>
</div>
</div>
<div class="row vertical-middle top-buffer">
<div class="col-md-6 col-md-push-6">
<img src="http://www.hercampus.com/sites/default/files/2013/02/27/topic-1350661050.jpg" class="center-block img-responsive">
</div>
<div class="col-md-6 col-md-pull-6 text-center">
<h2>Title 2</h2>
<p>Text to be centered</p>
</div>
</div>
</div>
</div>
</div>

Getting rid of padding or marging from bootstrap columns

I'm using bootstrap (version 3.3.6) for the first time to make my site. Readed the docs and start to code. Excluding the <link>'s the code below is my site's structure:
<body>
<div class="container">
<div class="row">
<div class="col-sm-2 col-md-2 col-lg-2 col-lg-pull-1">
<div class="loader">
<div class="loader-bg">
...
</div>
</div>
</div>
<div class="col-sm-10 col-md-10 col-lg-10 col-lg-push-1">
<div class="black-box">
<p class="info-message">Coming <span>VERY</span> soon!</p>
<p class="text-message">Until then, my contacts:</p>
...
</div>
</div>
</div>
</div>
Using push and pull classes I thought I was removed padding for the columns. Setting the main div with 'class="container"' I have the result:
Changing to 'class="container-fluid"' the behavior remains strange. Notice shapes overlapping page:
What I want in my results is: the circle and rectangle (both are divs) remains aligned to the edges of the page (left and right) with no padding or marging. Following docs until now doesn't work. What this behavior occurs?
by default col-* have padding so you just need to reset them
[class^="col"] {
padding: 0
}
[class$="-2"] {
background: orange
}
[class$="-10"] {
background: grey
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="loader">
<div class="loader-bg">
...
</div>
</div>
</div>
<div class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
<div class="black-box">
<p class="info-message">Coming <span>VERY</span> soon!</p>
<p class="text-message">Until then, my contacts:</p>
...
</div>
</div>
</div>