SashayAway SashayAway - 3 months ago 7
CSS Question

How to change the Bootstrap default div position for small screens?

I am working with Bootstrap. I would like to change the default div position when the screen re-sizes to

sm/xs
(the default position is the purple div is over red, when you do your screen/windows smaller). Basically I would like to get what the below image shows.

I have tried to change it position with
push
and
pull
, but it doesn't work.

Thanks

Image1



<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="robots" content="index,follow">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
<div class="container">
<div class="row">
<div style="background-color:#8000ff; height:200px" class="col-md-8 col-sm-12">Example1</div>
<div style="background-color:red; height:200px" class="col-md-4 col-sm-12">Example2</div>

</div>
</div>
</body>

</html>




Answer

You can easily change the order of grid columns with .col-md-push-* and .col-md-pull-* modifier classes.

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="Keywords" content="">
  <meta name="robots" content="index,follow">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>

   <div class="container">
     <div class="row">
       <div style="background-color:red; height:200px" class="col-sm-12 col-md-4 col-md-push-8">Example2</div>
       <div style="background-color:#8000ff; height:200px" class="col-sm-12 col-md-8 col-md-pull-4 ">Example1</div>
     </div>
 </div>

</body>

</html>