02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Bootstrapping our HTML

In this tutorial, we’ll enhance the visuals of our project by integrating Bootstrap 4.0. Learn to download and add Bootstrap, style elements with predefined classes, and create responsive layouts using the Jumbotron component. By the end of this lesson, your HTML structure will look modern and professional.


Steps to Bootstrap Your HTML

1. Download and Add Bootstrap

Visit the Bootstrap website and download the source files.

  • Extract the files and locate the CSS folder in the dist/ directory.
  • Copy the bootstrap.css file (or the minified version, bootstrap.min.css) into your project directory:
public/  
│  
├── css/  
│   └── bootstrap.css  

2. Link Bootstrap to Your HTML

Edit your index.html file to include the Bootstrap CSS file:

<link rel="stylesheet" href="css/bootstrap.css">  

This will allow you to use Bootstrap's predefined styles and components in your HTML.


3. Style Buttons with Bootstrap Classes

Transform your existing link into a button by adding the appropriate Bootstrap classes.

Original Link:

<a href="#" class="btn btn-primary">Discover More</a>  

Explanation:

  • btn: Adds button styling.
  • btn-primary: Applies a primary color style.

Save and refresh your browser. The link will now appear as a styled button.


4. Create a Responsive Jumbotron

A Jumbotron component is a standout container often used for hero sections or highlights.

Wrap your existing content in a Jumbotron:

<div class="jumbotron jumbotron-fluid text-center">  
    <div class="container">  
        <h1>Building React User Interfaces</h1>  
        <p>With Bootstrap and SaaS</p>  
        <a href="#" class="btn btn-primary">Discover More</a>  
    </div>  
</div>  

Class Breakdown:

  • jumbotron: Creates the large, standout container.
  • jumbotron-fluid: Makes the container responsive to screen size.
  • text-center: Centers the text horizontally.
  • container: Ensures proper spacing and alignment for the content.

5. Add a Background Image

Enhance your Jumbotron by adding a background image:

<div class="jumbotron jumbotron-fluid text-center" style="background-image: url('images/background.jpg'); background-size: cover; color: white;">  
    <div class="container">  
        <h1>Building React User Interfaces</h1>  
        <p>With Bootstrap and SaaS</p>  
        <a href="#" class="btn btn-primary">Discover More</a>  
    </div>  
</div>  

Explanation:

  • background-image: Specifies the image. Ensure the file path points to the correct location.
  • background-size: cover;: Ensures the image covers the entire container.
  • color: white;: Changes text color for better contrast.

Key Takeaways

  • Bootstrap simplifies styling and ensures a consistent, responsive design.
  • The Jumbotron component is ideal for creating standout sections.
  • Combining Bootstrap classes with inline styles can achieve professional visuals quickly.

In the next lesson, we’ll transition back to JavaScript, enabling hot reloading for our project with Webpack and Webpack-Dev-Server.

Video Transcript

00:00In the last lecture, we created our server
00:03and it's time for us to move into the visuals
00:05and we're gonna be using Bootstrap to do that
00:08and actually bootstrap 4.0 which is the latest greatest
00:11as we're creating these recordings.
00:13Although the version doesn't matter as much,
00:15really just the logic flow of
00:17how we're building it out, that's what really matters.
00:19But in the process, we'll use the Bootstrap buttons
00:21and oh to the Bootstrap Jumbo drone to create a few visuals,
00:26a leaderboard really on our site.
00:28Let's jump right into it. Let's do it.
00:32Alright, let's start bootstrapping.
00:34And to do that, what we're gonna need
00:35to do is we're gonna want to download Bootstrap.
00:38Now I'm gonna be working with the version four
00:41that is currently in an alpha
00:42and you could find a link in the chapters links,
00:46but go ahead to whatever version you're gonna be running,
00:48if it's the alpha, a later version
00:49or even an earlier version.
00:51And just go ahead and download Bootstrap,
00:54download the source files in your source files.
00:56You will find among your source files a distribution folder
01:00where you will find the CSS and you can then copy Bootstrap
01:04or the bootstrap Min in our case.
01:06I'm just gonna go for Bootstrap
01:08and I'm gonna go ahead into our public folder,
01:12create here another folder, call it CSS.
01:14And I'm gonna drop inside of it our bootstrap.
01:18So make sure that you add that CSS file
01:21into your CSS folder.
01:23And then with that said, let's go ahead
01:25and add it into our document in the HTML.
01:28So I'm gonna link, and the RL is a style sheet
01:33and the path is
01:39CSS slash bootstrap css
01:43and we're gonna close this baby up, save it,
01:47and let's start testing it out.
01:49So let's start off with our, our link here
01:51and let's turn it into a button by going
01:53and setting it a class
01:55and defining it as a button once I've done that.
01:58And this is basically one of the, there's so many
02:00and you are more than encouraged to explore,
02:02bootstrap itself in the documentation
02:05to discover all the different types of layouts
02:07and examples and whatnot.
02:09But in our case, we're gonna go ahead
02:11and create a button similar to this button
02:12that we have right here.
02:14So starting off our button is gonna already start forming
02:17as a button, even though it's kind of hard to see it
02:19'cause it doesn't have a background at a default.
02:22So let's go ahead and set it with a background
02:24and say you're the primary button and by doing so
02:28and if I click you're refresh, we'll see
02:30that now we have your primary button added in as well.
02:35So let's go ahead and continue styling things up a little
02:38bit by taking a step further outside of that button.
02:41And for one is I really want this diviv to be a container
02:45and by default, by setting it
02:46as a A container, not as a content.
02:50So container, by setting it as a container,
02:54what's actually gonna happen, it's gonna bound it
02:56and box it up and set it up
02:59as a container which will space it out
03:01and maximize the maximum size it could be as well beyond
03:05that also is gonna center it in the stage
03:07and all other nice things that relate to it.
03:10Now beyond that, I also want to go
03:11and I'm gonna set up another diviv layer above this.
03:14And what I really am up to,
03:16and let me just do this, is I really want this
03:19to be a leader, a leaderboard you could say.
03:22And in in um, bootstrap, the way you do
03:27that is you defined it as a jumbotron
03:30and I want that jumbotron to be fluid so it'll resize
03:34with the user jumbo throne fluid.
03:38And I also want all the texts that living
03:40that is living within here from the extra small size
03:44and up to be centered.
03:47Now by the way, when this extra small thing,
03:50although we're not gonna get into the layouts yet of
03:53bootstrap, is really to define
03:56and say that this is for mobile phones
03:57or devices that are incredibly small.
04:00Whenever you define something
04:01for the smallest resolution possible,
04:03it will automatically define it for larger sizes as well,
04:07such as tablets which are described with SM or small
04:10or md which is medium, which is desktops
04:13or lg which is larger desktops.
04:16So in our case, what I'm basically saying is I want the text
04:19to be centered in all the different sizes.
04:22So with that said, let's go ahead and save this
04:24and if I go one more time and click here on refresh
04:27and we will see that now we're having a jumbotron.
04:29It's a much nicer, it's setup and configured beautifully.
04:33And last but not least, I really wanna set up
04:34and put here an image.
04:36And to do that I went ahead
04:37and I downloaded this image from Pixel Bay
04:41and you could find it in the descriptions
04:43of this chapter as well.
04:45So let me just go ahead
04:46and add this image into our images folder
04:49and I'm just going
04:51to throw it right in there 'cause I already got it.
04:53And what I'm gonna do is I'm gonna go ahead
04:55and just copy this image name and go right back into my HTML
05:00and in my HTML, I'm just gonna go ahead
05:02and set your style directly
05:04and I'm gonna set that style to be background image
05:09URL and that URL is gonna be in, in the folder image
05:13for jpeg.
05:17Close that up. I also want it to be
05:21not repetitive, but eh that's good enough for now.
05:25And how about we also, if we're already doing that
05:28and we're setting that jumbotron,
05:30we might also wanna go ahead
05:31and set the color to be white for our copy
05:34because if not, we won't be able to see our content.
05:36And if I go back in here to my element,
05:39our copy should now change colors
05:41and we should have an image behind it.
05:44Everything worked according to plan,
05:46which it seemed that it didn't.
05:48So let me go ahead and click on save
05:49'cause maybe I just didn't save it.
05:51And let's go ahead and click on
05:52refresh and I still don't see it.
05:53So let me go into my inspector to basically inspect
05:57what's the going on here, inspect element.
06:01So I definitely see this
06:02but it doesn't seem to actually be doing anything.
06:05So lemme go to the element
06:06and try to set up our background image
06:10directly just to see what will happen.
06:11So I'm gonna set the URL
06:13and then it's gonna be inside of our image folder
06:18and it's gonna be that jpeg
06:23and it def definitely does work.
06:24So we put here something wrong in our description.
06:28So let's double check and see what did I do wrong?
06:32Background image forest.
06:36And that's because we broke a line I believe.
06:39No, it's not because we broke a line,
06:40but let's just, oh, 'cause I didn't put your assignment.
06:42Uh, what silly, silly person I am
06:45because that is one command and that is another command.
06:47Okay, so let's save that.
06:49Let's go ahead and click your un refresher.
06:50We should now she that it has worked.
06:53Congratulations, you have just created your first jumbotron
06:58and button in Bootstrap
07:02In this lecture we made things more visual
07:04by using Bootstrap 4.0
07:06and it's time for us to move back from
07:09HTML back into our JavaScript
07:11because in our next lecture, even
07:13before we do any more changes, we're gonna go back
07:16to our web, set up our, our JavaScript, and make our website
07:20Automatically hot reload.
07:22Really cool things.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!