Right column on top in Bootstrap on mobile platform - html

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;
}
}

Related

how to change div align in mobile version

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

How to fix problem with bootstrap 4 grid system?

I am facing a problem with the Bootstrap-4 grid system. There are 12 columns, and whenever I use less than 12 columns, the rows are automatically centered. I want left alignment, how can this be fixed?
A snippet of my code:
<div class="row justify-content-start con-flex">
<?php foreach($books as $book):?>
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<div id="single-book">
<div id="book-image">
<?php print '<img src = "'.strip_tags($book->book_image).'" alt = "">';?>
<div id="addto-cart"><i class="fas fa-shopping-cart"></i> Add to cart</div>
</div>
<div class="book-text">
<div id="book-name"><?= substr(htmlentities($book->book_name),0,21) ?></div>
<div id="author">By <i><?= htmlentities($book->author) ?></i></div>
<div id="price"><?= htmlentities($book->price) ?>.TK</div>
<div id="book-details">
<?php print 'View details'; ?>
</div>
</div>
</div>
</div>
<?php endforeach;?>
</div>
image of code:
enter image description here
According to Bootstrap doc that should solve your problem
<div class="container">
<div class="row justify-content-start">
<div class="col-4">
content here...
</div>
<div class="col-4">
content here...
</div>
</div>
</div>
The code you have should be working fine, columns will be aligned left by default; maybe what you are seeing is the result of using .container instead of .container-fluid which uses the full width of the viewport. It's either this or you might have some custom CSS that's affecting the layout of the columns
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row ">
<div class="col-4 col-md-4 border">content here...</div>
<div class="col-4 col-md-4 border">content here...</div>
</div>
</div>
<div class="container-fluid">
<div class="row ">
<div class="col-4 col-md-4 border">content here...</div>
<div class="col-4 col-md-4 border">content here...</div>
</div>
</div>
This problem was for my other base CSS.
Instead of:
*{
margin: 0 auto;
}
For this margin: 0 auto; in my main style.css file My bootstrap's grids were not working properly. Now I remove this margin: 0 auto from *.
Now
I write
* {
margin: 0;
padding: 0;
}
Now my bootstrap grids are working properly

Stacking using boostrap Grid System

I am building a header using Bootstrap. I'm trying to make the desktop version spread out over the full 12 grid like so:
Then on the phone I'm wanting to having the two stack like shown below:
This is the way I've been trying to accomplish so far with bootstrap but I am not having much luck: Any feedback or suggestions appreciated!
<div class="container-fluid">
<div class="background row">
<div class="col-lg-1 col-xs-12">
<p class="text-center">gb</p>
</div>
<div class="col-lg-1 col-xs-12">
<p class="text-center">us</p>
</div>
<div class="col-lg-6 col-xs-12">
<p class="text-center announce-something-h">ANNOUNCE SOMETHING HERE</p>
</div>
<div class="col-lg-4 col-xs-12">
<p class="text-center announce-something-h">UK</p>
</div>
Just use floats and media queries:
.header{
background-color:grey;
overflow:hidden;
}
.header__left, .header__right, .header__message{
padding:10px;
}
.header__left{
float:left;
}
.header__right{
float:right;
}
.header__message{
text-align:center;
background-color:red;
}
#media(max-width:767px){
.header__message{
clear:both;
}
}
<header class="header">
<div class="header__left">
GB
USD
</div>
<div class="header__right">
UK
</div>
<div class="header__message">Announce Something here</div>
</header>
live example:
https://codepen.io/anon/pen/PdXBZR

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>