V.Prasad
V.Prasad

Reputation: 151

change bootstrap grid column order when page in mobile view

I have one html page where i have 4 column in one row. When i load the page in desktop view then i can see all four columns perfectly, But when i check the same in mobile view then all div are showing one by one.

I need here to show two columns each row in mobile view.

e.g: Desktop view

[a] [b] [c] [d]

Mobile view:

[a] [b]

[c] [d]

I am currently using bootstrap version 3.3.7.

Below are complete html:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
     <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" type="text/javascript"></script> -->
    
<script type="text/javascript">


</script>
<style type="text/css">
.site-footer
{
  background-color:#26272b;
  padding:45px 0 20px;
  font-size:15px;
  line-height:24px;
  color:#737373;
}
.alert {
   width:108px;
}
</style>
</head>
<body>

  <div class="container">
  <div class="row">
        <div class="col-sm-3">
           <div class="alert alert-info">a</div>
        </div>
        <div class="col-sm-3">
           <div class="alert alert-danger">b</div>
        </div>
        <div class="col-sm-3">
            <div class="alert alert-info">c</div>
       </div>
        <div class="col-md-3">
           <div class="alert alert-info">d</div>
       </div>
     </div>
     
   
  
</div>
</body>
<script>


</script>
</html>

Please suggest.

Upvotes: 0

Views: 129

Answers (2)

Md.Shahjalal
Md.Shahjalal

Reputation: 413

Bootstrap 3, we use col-xs- to make columns on mobile device

<!DOCTYPE html>
 <html lang="en">
   <head>
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
   <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" type="text/javascript"></script> -->

  
  </head>
<body>

<div class="container">
    <div class="row">
        <div class="col-xs-6 col-sm-3">
          <div class="alert alert-info">a</div>
         </div>
        <div class="col-xs-6 col-sm-3">
          <div class="alert alert-danger">b</div>
        </div>
        <div class="col-xs-6 col-sm-3">
          <div class="alert alert-info">c</div>
        </div>
       <div class="col-xs-6 col-md-3">
         <div class="alert alert-info">d</div>
       </div>
     </div>
  </div>
</body>

Upvotes: 1

FluffyKitten
FluffyKitten

Reputation: 14312

In bootstrap 3, you can use col-xs- to make columns on mobile screens.

The code below makes 2 columns on tablets and mobiles, and 4 columns on larger screens:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

<div class="container">
 <div class="row">
   <div class="col-xs-6 col-md-3">
     <div class="alert alert-info">a</div>
   </div>
   <div class="col-xs-6 col-md-3">
     <div class="alert alert-danger">b</div>
   </div>
   <div class="col-xs-6 col-md-3">
     <div class="alert alert-info">c</div>
   </div>
   <div class="col-xs-6 col-md-3">
     <div class="alert alert-info">d</div>
   </div>
 </div>
</div>

Upvotes: 1

Related Questions