Skip to content

4.3 Bootstrap Grid System

Overview
Learn how to code Bootstrap components and grid system.
Excerpt Exercise 4.2.1

A quick guide to using Bootstrap components.

  1. Go to https://getbootstrap.com/
  2. Click on Docs https://getbootstrap.com/docs/5.3/getting-started/introduction/
  3. Scroll to code example #2 and copy/paste this code (with the CSS and JS links already in place) into a new HTML document or Codepen.
  4. Click on Components > Buttons and paste in some example buttons https://getbootstrap.com/docs/5.3/components/buttons/
<button type="button" class="btn btn-primary">Primary</button>
  1. Note the class names of other button variants. Change your button by editing the class name only.
<button type="button" class="btn btn-success">Success!</button>
  1. Continue exploring other components like Alerts, Carousel, and Modal.

Diagram showing bootstrap classes

  1. Bootstrap’s .container-fluid class always expands to the full width of the window, while the .container class has a maximum width. The .col class will expand to fill the width of the row on that container. Add multiple columns (in this case 3) and you will see that number of equally-sized columns per row.
  2. The .col-{rows} classes will take up only as many of the 12 Bootstrap columns as you define. The only rule is that the column and offset spans together add up to 12.
  3. Mix and match Bootstrap column sizes however you like.
  4. The .col-{breakpoint}-{rows} classes span the Bootstrap columns, but only on the breakpoint you define (and larger). So, while example#3 .col-4 remains the same, in example#4 .col-12 .col-md-4 defaults to the full width, except on medium breakpoints and higher. This allows for different layouts with the same content across different device sizes.
  5. The offset classes can center the columns in a container.
  6. There are also helper classes to control how elements are displayed.

A screenshot showing code autocompletion in VS Code. Most editors let you type the beginning of an HTML element and press tab to add the open and close tag you want. This feature also lets you add HTML elements with their class names by typing the full name of the selector.

A screenshot showing code completed so far. A three column layout coded.

A screenshot of the image in the second column. The image in the second column is not scaling or reflowing like the text.

A screenshot showing before and after adding spacing above the heading Notice the difference in negative space before and after we added top margin to the heading.

Left aligned text Notice that, aside from the masthead (the name of the publication), all text is left-aligned. Left aligned text has a straight edge on the left side that helps readers scan and find content. And, it’s easier to read because each line starts at the same horizontal origin, whereas center-aligned text has a ragged left edge causing readers to search for the start of each line.

An image showing the headings in the Bootstrap framework. The headings in the Bootstrap framework scale at consistent values.

Our final composition Our final composition https://criticalwebdesign.github.io/book/04-on-the-grid/4-3/index.html for multiple breakpoints seen in the browser with DevTools. The Toggle Device Toolbar (see the cursor in the upper right corner of the top image) enables you to view your work across multiple devices in the Chrome browser.