Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

4 column responsive in Bootstrap

I want to make a row with 4 columns. When the user uses a tablet the row will have 2 columns and the remaining 2 will jump under the row.

Then when the user uses mobile the row will have 1 column and the other columns will jump under each other.

Can you help me with this? I've tried this:

    <div class="col-md-3 col-sm-6 col-xs-12">
    </div>
    <div class="col-md-3 col-sm-6 col-xs-12">
    </div>
    <div class="col-md-3 col-sm-6 col-xs-12">
    </div>
    <div class="col-md-3 col-sm-6 col-xs-12">
    </div>
like image 305
Ahmad Abed Avatar asked Mar 11 '23 08:03

Ahmad Abed


1 Answers

The issue seems to be the margin or border that you may have to those for divs. Also you always have to wrap them in a <div class="row">

give all of them a single class (say "bootCols") and add this css:

.bootCols{
    margin:0;
    box-sizing:border-box;
    padding:5px;
    border:2px solid auto;
}

you can remove/edit padding and border in this css as you require

Here's live example:

.bootCols{
  height:100px;
  margin:0;
  box-sizing:border-box;
  padding:5px;
  border:2px solid black;
  background-color:red;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
  <div class="container">
    <div class="row">
      <div class="col-md-3 col-sm-6 col-xs-12 bootCols">
      </div>
      <div class="col-md-3 col-sm-6 col-xs-12 bootCols">
      </div>
      <div class="col-md-3 col-sm-6 col-xs-12 bootCols">
      </div>
      <div class="col-md-3 col-sm-6 col-xs-12 bootCols">
      </div>
    </div>
  </div>
like image 94
ab29007 Avatar answered Mar 15 '23 22:03

ab29007