In this installment of our Bootstrap 3 tutorial, we build a modal. Modals are streamlined, but flexible, dialog prompts with the minimum required functionality and smart defaults.
Hey everybody this is Christopher Gimmer from BootstrapBay and welcome to the seventh installment of our Bootstrap 3 tutorial. Today we’re going to be covering modals which are basically pop-up boxes.
To give you a preview of what we’re going to be doing today, if you click on our contact button our modal pops up and brings it to the foreground while greying out the rest of the site. Then we can close that off and we’re back to the main page. So that’s what we’re going to be building today and let’s dive right in.
Now we want to scroll down to the end of our website. We want to make sure that we put the jQuery code at the bottom of the page so that it loads faster. HTML loads from top to bottom so this ensures a more efficient loading process. When people land on your page, it usually takes them a few seconds to digest everything on the page before they go clicking around everywhere.
Next we’re going to div class equal to modal-dialog and then div class equal to modal-content. This is basically the structure for the modal, and then we can start building it out.
Now we’re going to start on the header with div class equal to modal-header. Inside here we’ll go with an h4 tag and name it contact. If we go to our preview and we click on contact, we have our modal appearing styled with the header. Right now we don’t have our close button created yet so to dismiss just click outside of the modal to bring you back.
Next we’re going to create the body. Within our model-content class, we’re going to create another class called modal-body. In here we’ll add a paragraph tag and we’ll say for general inquiries please email [email protected] Now when we go back to our preview, you can see there’s a header with a body and it’s all styled properly.
The last thing we’re going to do is add our footer with a button. Still within our modal-content, we’re going to create another class, as you might have guessed, modal-footer. The naming does make sense. Here we’re going to create our close button. Just like any other button, we’ll go a class equal to ‘btn btn-primary’ then we’ll go data-dismiss equal to modal. This is basically going to trigger the dismiss function for the modal and we’ll name the button ‘close’.
Now when we go back to our preview, click on contact and we have our modal all completed. We have our header, text within our body, then we have our footer and our close button. If we click on that, it dismisses the modal properly.
So that’s pretty much it for our tutorial on modals. Obviously you can get quite intricate and build a form or anything you really want in here and customize it any way you like. In the next video, we’re going to add thumbnails to our theme content just to make the page a little nicer. Make sure to subscribe, comment and we’ll see you in the next video.