8 min read

Asset 1

A 10 brief to explain react and it's perks

Finally, Bootstrap 4 has arrived!


There is light at the end of the tunnel and it is NOT Chuck Norris holding a flashlight. Finally, someone fixed CSS. This is a library made by Mark Otto and Jacob Thornton – normal people – developers like you and me, and they did great!

These two guys working on Twitter were suffering the same problems we have been with HTML and CSS. Fed up with the situation, they decided to build a base CSS Sheet designed to be imported into any website. It makes every front-end development work 4x’s easier.

bootstrap 4

Besides, Bootstrap gives you a dozen of new elements that you would normally want to use but don’t actually exist in CSS+HTML: The Bootstrap components.

Layouts: Solving the Box Model


One of the broken things in CSS is the way that layouts work – working with float, display and position sucks. This is how Bootstrap solved it:

Everything is now divided into Rows and Columns.

Bootstrap creators replicated the same concept that <tables> had, but instead of using tables, they used <div> (boxed containers). They can’t create their own HTML tags because that will require a new HTML version and would make Bootstrap incompatible with current browsers. Tags must stay the same – that’s why they decided to override the <div> default behaviors with classes.

This is a row: <div class="row">
This is a column: <div class"col–sm–x">

bootstrap tutorial

Bootstrap has divided the width of the screen in 12 slots – each of them with 8,33% of the total width of the row. The size of 1 column, can be between 1 and 12 slots.

On the flip side, columns were made to live within the rows (just like what happens between <td> and <tr>). You always need to open a row before opening a column. All columns in a row must always add up to a maximum of 12 slots.

bootstrap tutorial

Our first Layout example:


Just like we did in the Layout chapter of the course, let’s create one page with 2 big sections: one sidebar on the right and one main content on the left.

Bootstrap is 100% Responsive


It’s very easy to decide how your website will render in different screen sizes; when you add each column into the rows you need to assign a class with the following format:

<div class="col–md–x">
Colmdx
Means that this element should behave like a Bootstrap column.Means that I am specifying only for the devices with a "medium" sized screen.Specifies how many slots I want this column to take (remember you can take a max of 12 slots per row).
☝Bootstrap device sizes:PhonesBig-phone/small-tabletTabletsDesktopsExtra-large desktops
 Nothingsmmdlgxl

☝Note: if you don’t specify the screen size (ex. by using 'sm', 'md', or 'xl'), the website will be rendered for mobile phones by default.

Defining Mobile, Tablet, and Desktop at the same time


We are going to set the layout (using the sm, md and lg column classes) for two rows in all the devices at the same time:

bootstrap 4

<!-- Stack the columns on mobile by making one full-width and the other half-width --> 
<div class="row">
  <div class="col-12 col-md-8">.col-12 .col-md-8</div>
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>

<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop --> 
<div class="row">
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>

<!-- Columns are always 50% wide, on mobile and desktop --> 
<div class="row">
  <div class="col-6">.col-6</div>
  <div class="col-6">.col-6</div>
</div>

Basic Bootstrap 4 Skeleton


We already know the basic HTML5 skeleton any website needs to have. Now you just have to add a few lines in your skeleton to make it "Bootstrap compatible":

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

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  </body>
</html>

Remember, Bootstrap is just a stylesheet. That’s why it is very simple to include in your website. You use the <link> tag to include the styles, and, optionally, use the javascript <script> tag to include the Bootstrap Javascript files.

The Bootstrap Javascript functionality requires the jQuery and Popper Javascript libraries to be included first. You don’t need to know the details about this yet. Just include the JS libraries using the script tag and later you will understand.

🔗 Here you can find some great Bootstrap files to get you started.

Bootstrap 4 Components


HTML is so basic, it only has a few tags – we know that already. But when you browse the web today, you see a different thing… websites today have menus, icons, load-bars, navbars, labels, etc. Where are those tags? None of those tags are defined in HTML!

Every developer has to fake these additional elements every time they create a new website. They have to do everything from scratch, and it takes a lot of time.

When you import Bootstrap into your website, you will have a new set of components at your disposal. This is just a small part of those elements:

bootstrap 4

These are the most Important and Used Components in this Bootstrap tutorial:


The NavBar

This is so popular that it’s in the menu of 99% of all websites. It normally has the logo of the company and a series of links – depending on each website’s business logic.

Here is an example of how a NavBar may look on a website:

bootstrap tutorial

<nav class="navbar navbar-expand-lg navbar-light bg-light">
            <div class="container">
                <a class="navbar-brand" href="#">Website Brand</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNavDropdown">
                    <ul class="navbar-nav ml-auto">
                        <li class="nav-item active">
                            <a class="nav-link" href="#">
                                <a class="btn btn-success">Create a new post</a>
                            </a>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                Settings
                            </a>
                            <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                                <a class="dropdown-item" href="#">Action</a>
                                <a class="dropdown-item" href="#">Another action</a>
                                <a class="dropdown-item" href="#">Something else here</a>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>

The Card

This is probably the most used Bootstrap component, every website has a few card because it is ideal to list items in a beautiful way. Some examples of the Card used can be:

  • The "team" section of a website where you list the different employees.
  • The typical Pinterest wall.
  • Any social media feed like Instagram, Facebook, twitter, etc.

Here is an example of how a "The Card" may look on a website:

bootstrap 4

<div class="card" style="width: 20rem;">
  <img class="card-img-top" src="..." alt="Card image cap">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

The Modal

Everyone hates a modal, it is super annoying, always asking you to subscribe to a newsletter! 🙂

Here is how a modal looks by default on Bootstrap.

bootstrap 4

div class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Save changes</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

☝Important! The Modal needs Javascript in order to work. Remember to include the three Javascript files that are needed in a typical Bootstrap Skeleton: jQuery, Popper and Bootstrap.js

What you really need to know about Bootstrap


Bootstrap official documentation is amazing!! We don’t need to start copying and pasting all their posts. Please visit the following and focus on reading these topics:

Earn RE2PECT.


Success does not come overnight. This is your first real achievement. Let me ask you, do you feel capable using HTML, CSS, Layouts and Bootstrap? Don’t lie to yourself.

No more lessons on these topics – it is time to deliver. Your attention must be focused on the class projects. Remember to live by the developer values. Chill.