container
, row
en col
<div class="container">...</div>
container-fluid
voor als je 100% van de schermbreedte wil innemen.container
<div class="container"> <h1>Hello Container</h1> </div>
<div class="row">...</div>
<div class="container"> <div class="row"> <h1>Hello Row</h1> </div> </div>
<div class="col">...</div>
col-12
, col-11
, col-7
, etc.<div class="col-3">...</div>
col-sm-12
, col-md-6
, col-lg-4
, col-xl-3
, etc.<div class="container"> <div class="row"> <div class="col-6"> <h1>Hello Column</h1> </div> <div class="col-6"> <h1>Hello Another Column</h1> </div> </div> </div>
De grid van Bootstrap duurt eventjes om gewoon te geraken. We proberen het meteen uit in een project die we vervolgens als referentie gaan gebruiken om het beter te begrijpen.
hello-bootstrap-grid
.index.html
.div.container
, div.row
en div.col
(met getal) om te experimenteren met inhoud die zich automatisch houdt aan de meegegeven breedte (zie voorbeeld).<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <title>Hello Bootstrap Grid</title> </head> <body> <div class="container"> <div class="row"> <div class="col-12"> <h1>Hello Bootstrap Grid</h1> <p>To learn about how Bootstrap's grid works, I'm trying out all the different <code>col-12</code>, <code>col-6</code>, <code>col-4</code>, etc. </p> <h2>Hello col-12</h2> <p>I take up 12 out of 12 possible spaces in a row, so I'm neatly taking up all of the space of this row. </p> <img src="https://picsum.photos/1800/300" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta repudiandae tempore veritatis. Fugiat tempore quibusdam temporibus similique atque exercitationem ipsum quae qui dignissimos, doloribus nobis perspiciatis officia eligendi maiores accusamus quisquam odio voluptate non modi, soluta delectus?</p> </div> <div class="col-6"> <h2>Hello col-6</h2> <p>I take up 6 out of 12 possible spaces in a row, so I'm neatly taking up half the space of this row. </p> <img src="https://picsum.photos/800/250" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-6"> <h2>Hello col-6</h2> <p>I take up 6 out of 12 possible spaces in a row, so I'm neatly taking up half the space of this row. </p> <img src="https://picsum.photos/800/250" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-4"> <h2>Hello col-4</h2> <p>I take up 4 out of 12 possible spaces in a row, so I'm neatly taking up a third of the space of this row. </p> <img src="https://picsum.photos/800/251" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-4"> <h2>Hello col-4</h2> <p>I take up 4 out of 12 possible spaces in a row, so I'm neatly taking up a third of the space of this row. </p> <img src="https://picsum.photos/800/251" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-4"> <h2>Hello col-4</h2> <p>I take up 4 out of 12 possible spaces in a row, so I'm neatly taking up a third of the space of this row. </p> <img src="https://picsum.photos/800/251" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-3"> <h2>Hello col-3</h2> <p>I take up 3 out of 12 possible spaces in a row, so I'm neatly taking up a quarter of the space of this row. </p> <img src="https://picsum.photos/800/249" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-3"> <h2>Hello col-3</h2> <p>I take up 3 out of 12 possible spaces in a row, so I'm neatly taking up a quarter of the space of this row. </p> <img src="https://picsum.photos/800/249" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-3"> <h2>Hello col-3</h2> <p>I take up 3 out of 12 possible spaces in a row, so I'm neatly taking up a quarter of the space of this row. </p> <img src="https://picsum.photos/800/249" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-3"> <h2>Hello col-3</h2> <p>I take up 3 out of 12 possible spaces in a row, so I'm neatly taking up a quarter of the space of this row. </p> <img src="https://picsum.photos/800/249" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-3"> <h2>Hello col-3</h2> <p>I take up 3 out of 12 possible spaces in a row, so I'm neatly taking up a quarter of the space of this row. </p> <img src="https://picsum.photos/800/249" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-3"> <h2>Hello col-3</h2> <p>I take up 3 out of 12 possible spaces in a row, so I'm neatly taking up a quarter of the space of this row. </p> <img src="https://picsum.photos/800/249" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-3"> <h2>Hello col-3</h2> <p>I take up 3 out of 12 possible spaces in a row, so I'm neatly taking up a quarter of the space of this row. </p> <img src="https://picsum.photos/800/249" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> <div class="col-3"> <h2>Hello col-3</h2> <p>I take up 3 out of 12 possible spaces in a row, so I'm neatly taking up a quarter of the space of this row. </p> <img src="https://picsum.photos/800/249" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quos magnam deleniti tempore reiciendis, corporis inventore omnis excepturi, expedita nulla dignissimos minima obcaecati quas praesentium. Iste, nihil enim, dignissimos amet nobis eligendi atque voluptatem tempora velit perferendis molestiae.</p> </div> </div> </div> <!-- Optional JavaScript; choose one of the two! --> <!-- Option 1: Bootstrap Bundle with Popper --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> <!-- Option 2: Separate Popper and Bootstrap JS --> <!-- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script> --> </body> </html>
col-sm-6
is voor small, col-md-6
is voor medium, col-lg-6
is voor large, etc.)<div class="container"> <div class="row"> <div class="col-12"> <h1>Hello Responsive Bootstrap Grid</h1> ... </div> <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3"> ... </div> <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3"> ... </div> <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3"> ... </div> <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3"> ... </div> </div> </div>
Het voorbeeld van hier boven gaan we overnemen om de responsive grid van Bootstrap beter te begrijpen.
hello-bootstrap-grid
project, maak een nieuw bestand aan genaamd responsive.html
.div.container
, div.row
en div.col
(met getal) om te experimenteren met inhoud die zich automatisch houdt aan de meegegeven breedte (zie voorbeeld) en die ook automatisch verandert afhankelijk van schermgrootte.<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <title>Hello Responsive Bootstrap Grid</title> </head> <body> <div class="container"> <div class="row"> <div class="col-12"> <h1>Hello Responsive Bootstrap Grid</h1> <p>To learn about how Bootstrap's responsive grid works, I'm trying out all the different <code>col-sm-12</code>, <code>col-md-6</code>, <code>col-lg-4</code>, etc. </p> </div> <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3"> <h2>Hello col-sm-12 col-md-6 col-lg-4 col-xl-3</h2> <p>When the screen is small I'm col-12, when it's medium I'm col-6, when it's large I'm col-4, when it's extra large im col-3! </p> <img src="https://picsum.photos/1800/750" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta repudiandae tempore veritatis. Fugiat tempore quibusdam temporibus similique atque exercitationem ipsum quae qui dignissimos, doloribus nobis perspiciatis officia eligendi maiores accusamus quisquam odio voluptate non modi, soluta delectus?</p> </div> <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3"> <h2>Hello col-sm-12 col-md-6 col-lg-4 col-xl-3</h2> <p>When the screen is small I'm col-12, when it's medium I'm col-6, when it's large I'm col-4, when it's extra large im col-3! </p> <img src="https://picsum.photos/1800/750" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta repudiandae tempore veritatis. Fugiat tempore quibusdam temporibus similique atque exercitationem ipsum quae qui dignissimos, doloribus nobis perspiciatis officia eligendi maiores accusamus quisquam odio voluptate non modi, soluta delectus?</p> </div> <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3"> <h2>Hello col-sm-12 col-md-6 col-lg-4 col-xl-3</h2> <p>When the screen is small I'm col-12, when it's medium I'm col-6, when it's large I'm col-4, when it's extra large im col-3! </p> <img src="https://picsum.photos/1800/750" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta repudiandae tempore veritatis. Fugiat tempore quibusdam temporibus similique atque exercitationem ipsum quae qui dignissimos, doloribus nobis perspiciatis officia eligendi maiores accusamus quisquam odio voluptate non modi, soluta delectus?</p> </div> <div class="col-sm-12 col-md-6 col-lg-4 col-xl-3"> <h2>Hello col-sm-12 col-md-6 col-lg-4 col-xl-3</h2> <p>When the screen is small I'm col-12, when it's medium I'm col-6, when it's large I'm col-4, when it's extra large im col-3! </p> <img src="https://picsum.photos/1800/750" class="img-fluid" alt="" srcset=""> <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Soluta repudiandae tempore veritatis. Fugiat tempore quibusdam temporibus similique atque exercitationem ipsum quae qui dignissimos, doloribus nobis perspiciatis officia eligendi maiores accusamus quisquam odio voluptate non modi, soluta delectus?</p> </div> </div> </div> <!-- Optional JavaScript; choose one of the two! --> <!-- Option 1: Bootstrap Bundle with Popper --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> <!-- Option 2: Separate Popper and Bootstrap JS --> <!-- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script> --> </body> </html>
We gaan oefenen op wat we geleerd hebben oefenen aan de hand van een leuke Pokémon oefening. We gaan namelijk de eerste 17 Pokémon weergeven op een responsieve manier.
pokemon
en maak gebruik van Bootstrap om een responsieve webpagina met Pokémon te tonen zoals in het voorbeeld.index.html
aan.