cssbootstrap-4viewportbootstrap-5bootstrap-grid

Bootstrap grid is not working on codeply or devtools. size of <div class="col-lg-3 col-md-4 col-sm-6"> is not changing


I tried using viewport meta tag in head.
I tried using a div class="container" around it.
no matter what i do. its not working on codeply, and chrome devtools. but its working when i change my browser size. i tried using different bootstrap versions but its not working.

<!doctype html>
<html lang="en">
  <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
  
 

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
<div class="container">


    <div class="row">
      <div class="col" style="background-color:red; border: 1px solid;">
          col
      </div>
      <div class="col" style="background-color:red; border: 1px solid;">
          col
      </div>
  </div>

  <div class="row">
      <div class="col-6" style="background-color:green; border: 1px solid">
          col-6
      </div>
      <div class="col-6" style="background-color:green; border: 1px solid">
          col-6
      </div>
  </div>

  <div class="row">
      <div class="col-lg-3 col-md-4 col-sm-6 " style="background-color:yellow; border: 1px solid">
          col-lg-3 col-md-4 col-sm-6
      </div>
      <div class="col-lg-3 col-md-4 col-sm-6" style="background-color:yellow; border: 1px solid">
          col-lg-3 col-md-4 col-sm-6
      </div>
      <div class="col-lg-3 col-md-4 col-sm-6" style="background-color:yellow; border: 1px solid">
          col-lg-3 col-md-4 col-sm-6
      </div>
      <div class="col-lg-3 col-md-4 col-sm-6" style="background-color:yellow; border: 1px solid">
          col-lg-3 col-md-4 col-sm-6
      </div>
  </div>
</div>
  
  </body>
</html>


Solution

  • col-sm-6 is not for mobiles. You need to use just col-6. col-sm-6 reffers for width >= 576px.