I have to re-arrange column in small screen column which are in following sequence 1,2,3 should show as 3,1,2 in small screen.
It works fine with two but i am not sure how to make it work with three column with the following structure
<div class="container-fluid">
<h1>Push and Pull</h1>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="col-md-6" style="background-color:lavender;">1</div>
<div class="col-md-3" style="background-color:lavenderblush;">2</div>
<div class="col-md-3" style="background-color:green;">3. This should be first one on small screen</div>
</div>
</div>
https://codepen.io/anon/pen/zjZJRG
I tried few but it breaks the design not sure if it will work with three column.
As you are working with BS3, you can use the following HTML structure:
<div class="row">
<div class="col-xs-12 col-md-3 pull-right">3</div>
<div class="col-xs-12 col-md-6">1</div>
<div class="col-xs-12 col-md-3">2</div>
</div>
Demo:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<h1>Push and Pull</h1>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="col-xs-12 col-md-3 pull-right" style="background-color:green;">3. This should be first one on small screen</div>
<div class="col-xs-12 col-md-6" style="background-color:lavender;">1</div>
<div class="col-xs-12 col-md-3" style="background-color:lavenderblush;">2</div>
</div>
</div>
If you are using bootstrap 4 then you can use flex class to manage that. In this case you can use order-*.
<html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<h1>Push and Pull</h1>
<p>Resize the browser window to see the effect.</p>
<div class="row d-flex">
<div class="col-md-6 order-sm-2" style="background-color:lavender;">1</div>
<div class="col-md-3 order-sm-1" style="background-color:lavenderblush;">2</div>
<div class="col-md-3 order-sm-0" style="background-color:green;">3. This should be first one on small screen</div>
</div>
</div>
</body>
</html>
Related
I have an issue with bootstrap columns and can't seem to resolve swapping the order on smaller devices. I don't want these to stack because they stay a single row on desktop, tablet and mobile. However, on Desktop and tablet I want the row in the default order like this:
Logo Menu Button
But on phones, I simply want the first two columns swapped, like so:
Menu Logo Button
How can I achieve a simple reverse of the columns while keeping the row?
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-lg-6 col-xs-4 col-xs-order-2">
Logo
</div>
<div class="col-lg-6 col-xs-4 col-xs-order-1">
Menu
</div>
<div class="col-xs-4 hidden-lg col-xs-order-3">
Button
</div>
</div>
</div>
Update:
screenshot of current result
The issue is that Bootstrap-4 dropped the order-xs class as it is the default class. If you want to apply changes for only xs-classes you have to change the roder for all elements and use order-sm--class to correct the order at sm-width:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-lg-6 col-xs-4 order-2 sm-order-1">
Logo
</div>
<div class="col-lg-6 col-xs-4 order-1 sm-order-2">
Menu
</div>
<div class="col-xs-4 hidden-lg order-3 sm-order-3">
Button
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-xs-4">
Menu
</div>
<div class="col-lg-4 col-md-4 col-xs-4 order-sm-first">
Logo
</div>
<div class="col-lg-4 col-md-4 col-xs-4 hidden-lg">
Button
</div>
</div>
</div>
I'm using Bootstrap I have coded this:
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-12 col-md-12 col-sm-12 col-12 mb-xl-0 mb-lg-5 mb-md-5 mb-sm-5 mb-5">
<div class="slider-slick-img container">
<div class="slider-for">
IMAGE GOES HERE
</div>
<div class="slider-nav mt-5">
<div class="item px-2">
THUBMNAIL GOES HERE
</div>
</div>
</div>
</div>
<div class="col-xl-8 col-lg-12 col-md-12 col-sm-12 col-12 mb-xl-0 mb-lg-5 mb-md-5 mb-sm-5 mb-5">
<div class="">
CONTENT GOES HERE
...
</div>
</div>
</div>
</div>
And the result of this code goes here:
As you can see it separates the columns of images and the column of contents (product title, product description & etc).
However they are both placed in one row class.
So how to properly place them together in one row as the expected result shows here?
Expected Result:
UPDATE #1
If I remove col-lg-12 col-md-12 col-sm-12 from <div class="col-xl-4 col-lg-12 col-md-12 col-sm-12 col-12 mb-xl-0 mb-lg-5 mb-md-5 mb-sm-5 mb-5"> of the images column & content column, and also add col-6 instead of col-12 to both column classes, this result will appears:
However, as you can see, the content looks thinner and still have differences with the Expected Result image.
So how to solve this issue?
You're repeating the classes and simply complicated everything here, you have to define where you want break to full row it'll automatically break at that screen size, you needn't explicitly add another class, adding too many classes will confuse you and anyone who has to understand the code later. https://getbootstrap.com/docs/4.0/layout/grid/
<header>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</header>
<div class="container">
<div class="row">
<div class="col-sm-6 ">
<div class="">
<h1>
Cat
</h1>
<p>
The cat is a domestic species of small carnivorous mammal. It is the only domesticated species in the family Felidae and is often referred to as the domestic cat to distinguish it from the wild members of the family.
</p>
</div>
</div>
<div class="col-sm-6 ">
<div class="slider-slick-img container">
<div class="slider-for">
<img src="https://static.toiimg.com/photo/msid-67586673/67586673.jpg?3918697" width="100%" />
</div>
<div class="slider-nav mt-5">
<div class="item px-2">
<img src="https://static.toiimg.com/photo/msid-67586673/67586673.jpg?3918697" width="100px" />
</div>
</div>
</div>
</div>
</div>
</div>
In both of your columns you have added the class col-12 which means that by default those columns will take all the row UNTIL you reach the first breakpoint which in this case would be col-sm. In order to fix this you have to specify col-6 instead of col-12 and if you check it in a screen size smaller than sm you'll notice each column is taking up to 6 places in the grid layout.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-6">
<div class="slider-slick-img container">
<div class="slider-for">
IMAGE GOES HERE
</div>
<div class="slider-nav mt-5">
<div class="item px-2">
THUBMNAIL GOES HERE
</div>
</div>
</div>
</div>
<div class="col-6">
CONTENT GOES HERE
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
Putting the div with content first and the one with the image after appears to mirror this layout correctly.
To define columns of equal width nothing more is needed than using class .col on each of them, as per official documentation (Bootstrap 5.0)
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col">
<div class="">
CONTENT GOES HERE
...
</div>
</div>
<div class="col">
<div class="">
IMAGE GOES HERE
</div>
<div class="">
<div class="">
THUBMNAIL GOES HERE
</div>
</div>
</div>
</div>
</div>
Remove container class applied with slider-slick-img. It is not needed. And kindly share the link to your code where we can check with actual content(images and add to cart box). Else, with these texts, it is working fine here.
You should not set 12 on lg screen for both div,
set 8,4 on xl,lg
set 6,6 on md
and set 12,12 on sm.
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-6 col-sm-12 col-12 mb-xl-0 mb-lg-5 mb-md-5 mb-sm-5 mb-5">
<div class="slider-slick-img container">
<div class="slider-for">
IMAGE GOES HERE
</div>
<div class="slider-nav mt-5">
<div class="item px-2">
THUBMNAIL GOES HERE
</div>
</div>
</div>
</div>
<div class="col-xl-8 col-lg-8 col-md-6 col-sm-12 col-12 mb-xl-0 mb-lg-5 mb-md-5 mb-sm-5 mb-5">
<div class="">
CONTENT GOES HERE
...
</div>
</div>
</div>
</div>
I solved your issue by opting for full responsive col's using grid system as shown in my code.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col">
<div class="">
CONTENT GOES HERE
...
</div>
</div>
<div class="col">
<div class="">
IMAGE GOES HERE
</div>
<div class="">
<div class="px-2">
THUBMNAIL GOES HERE
</div>
</div>
</div>
</div>
</div>
You should also include the meta tag "viewport" for your html code to be processed correctly by the browser.
<meta name="viewport" content= "width=device-width, initial-scale=1.0", shrink-to-fit=no">
You can try putting this in the section of your work.
I have more than 12 columns in the row which makes the columns stack vertically, but the top ones have different size compared to bottom ones.
<div class="container-fluid">
<div class="row">
<div class="col-md"></div>
<div class="col-md"></div>
<div class="col-md"></div>
<div class="col-md"></div>
<div class="col-md"></div>
</div>
</div>
I am trying to have responsive (allow grow) columns but all columns should carry same width.
You can try insert a col-md-4 with no content or insert only 2 col-md-4 on a row, See if this help you. Look at full screen. (Modified the answer with the help of the comments)
<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-md-4">
1
</div>
<div class="col-md-4">
2
</div>
<div class="col-md-4">
3
</div>
</div>
<div class="row">
<div class="col-md-4">
1
</div>
<div class="col-md-4">
2
</div>
<div class="col-md-4" id="last-column">
</div>
</div>
</div>
You don't need custom CSS for this. You should use the already defined responsive bootstrap classes for displaying. Also another .row is not needed but could be useful for another row.
<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-md-4">
1
</div>
<div class="col-md-4">
2
</div>
<div class="col-md-4">
3
</div>
<div class="col-md-4">
4
</div>
<div class="col-md-4">
5
</div>
<div class="col-md-4 d-none d-lg-block">
6
</div>
</div>
</div>
Here is a code I tried but not working especially in mobile view
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<div class="col-sm-4">
<div class="product_body">
<div class="prod_image">
<img src="images/product/1.png">
</div>
<div class="prod_details">
<h4>Teddy bear</h4>
<div class="row">
<div class="col-xs-12 col-md-6 prod_price">
RS 333
</div>
<div class="col-xs-12 col-md-6 prod_offer">
88% OFF
</div>
</div>
</div>
</div>
</div>
If I'm understanding correctly, You need a <div class="row" before col-sm-4.
EDIT: From your screenshot, I don't see a container, which you will need. Maybe it is already included but I cant see it.
You need to have <div class="container"> <div class="row"> <div class="col-sm-4">
Try removing the other divs first to see if that fixes your problem, then work on adding others in.
I am trying to divide a col-md-4 again in to a col-md-6 and col-md-6 and its not working what i was expecting was to get the two col-md-6s in the the same line .but i am getting the second col-md-6 beneath the first col-md-6.
Here is my HTML
<div class="col-md-1" style="background-color:lavender;">.col-md-2
<div class="col-md-10" style="background-color:red;">
red
</div>
<div class="col-md-1" style="background-color:green;">
green
</div>
</div>
Here is the fiddle illustrating the issue.Please update what has gone wrong or if this should be attained in some other way.
For the bootstrap grid system to work properly, the format should be row > col + col. In your code, you don't have any elements with a row class.
Bootstrap also has predefined classes for extra-small devices, small-devices, large-devices and you should use them appropriately depending upon what you want.
Read more about Bootstrap grid system here to understand it better.
Hence, this should work :
<div class="container-fluid">
<h1>Hello World!</h1>
<p>Resize the browser window to see the effect.</p>
<div class="row" style="background-color:lavender;">
<div class="col-md-6 col-sm-6 col-lg-6 col-xs-6" style="background-color:red;">
red
</div>
<div class="col-md-6 col-sm-6 col-lg-6 col-xs-6" style="background-color:green;">
green
</div>
</div>
</div>
Take note of col-md-6, col-sm-6 etc. They all define how these divs will look on different devices. Check out this example demo on the official Bootstrap site. For quick reference in the future, I am leaving this screenshot here (which explains these classes) :
Here is your updated Fiddle
you need to put a div class="row" inside the div class="col-md-1"
<div class="col-md-1" style="background-color:lavender;">.col-md-2
<div class="row">
<div class="col-md-10" style="background-color:red;">
red
</div>
<div class="col-md-1" style="background-color:green;">
green
</div>
</div>
</div>
If I'm not wrong then do you want this ? Click to see
<div class="container-fluid">
<h1>Hello World!</h1>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="col-md-2">
<div class="col-md-10" style="background-color:red; float:right">
red
</div>
<div class="col-md-1" style="background-color:green; float:right">
green
</div>
</div>
</div>
You need to use the .row class, try this:
<div class="col-md-1" style="background-color:lavender;">.col-md-2
<div class="row">
<div class="col-md-10" style="background-color:red;">
red
</div>
<div class="col-md-1" style="background-color:green;">
green
</div>
</div> </div>
Have a look at this link for more information