Search code examples
htmlcssmobileresponsive-designresolution

Bootstrap usage of col-x for multiple resolutions


I have the following code:

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="card">
      <div class="col-md-3" style="display: inline-block; float:left;">
        ... content ...
      </div>

      <div class="col-md-3" style="display: inline-block; float:left;">
        ... content ...
      </div>

      <div class="col-md-3" style="display: inline-block; float:left;">
        ... content ...
      </div>

      <div class="col-md-3" style="display: inline-block; float:left;">
        ... content ...
      </div>
    </div>
  </div>
</div>

These are 4 controls (inputs) and they display fine in desktop and mobile resolution, on desktop they are all next to each other and on mobile they are below each other.

I want it so that on smaller resolutions (mobile) there is 2 next to each other on the first line and 2 next to each other on the second line, but still in larger resolution they should display next to each other on 1 line, this for the purpose of "saving space", the controls don't need to take the complete line on there own because the input is limited.

I have tried but not succeeded to do so by playing with the col-md-x and by having less div's but I can't make it work.

How can I achieve this? Thank you for any direction or suggestion!


Solution

  • With col-6 on screens smaller than md your col-6 will put this divs 2 per row.I moved the row inside your card class

    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
      <div class="container">
     <div class="card">
    <div class="row">
       
        <div class="col-6 col-md-3 col-lg-3 co-xl-3">     
         ... content ...
        </div>
    
        <div class="col-6 col-md-3 col-lg-3 co-xl-3" >                
         ... content ...
        </div>
    
        <div class="col-6 col-md-3 col-lg-3 co-xl-3" >
        ... content ...
        </div>
    
        <div class="col-6 col-md-3 col-lg-3 co-xl-3" >
         ... content ...
        </div>
    </div>
    </div>