Reader small image

You're reading from  Bootstrap 4 Cookbook

Product typeBook
Published inJun 2017
Reading LevelBeginner
PublisherPackt
ISBN-139781785889295
Edition1st Edition
Languages
Right arrow
Author (1)
Ajdin Imsirovic
Ajdin Imsirovic
author image
Ajdin Imsirovic

Ajdin Imsirovic is a full-stack web developer who has published several courses on the subject of web design and web development. He has also authored three books, Bootstrap 4 Cookbook, Elm Web Development, and Vue.js Quick Start Guide. In his fourth book, Vue CLI 3 Quick Start Guide, he introduces readers to the rich ecosystem of frontend tooling and best practices.
Read more about Ajdin Imsirovic

Right arrow

Chapter 4. Diving Deep into Bootstrap 4 Components

In this chapter, we will cover:

  • Creating custom alerts and positioning them in the viewport
  • Making full-page modals
  • Altering the behavior of popups using tether options
  • Controlling the color and opacity of ToolTips using Sass variables
  • Using Bootstrap's Sass mixins to create custom buttons
  • Adjusting the rounding of corners on buttons and button groups
  • Controlling the number of card columns on different breakpoints with SCSS
  • Making cards responsive
  • Easily positioning inline forms

Creating custom alerts and positioning them in the viewport


In this recipe, we will create four alerts that will appear in the top-right corner of a web page. To see the final result, open the chapter4/complete code's app folder, and run the git bash command on it. Follow it up with the harp server command, and navigate to localhost:9000 in your browser to see the result we will achieve in this recipe.

Upon opening the web page as explained in the preceding paragraph, you should see the four alerts appearing one after the other. Click on the close button to close any of them, and note how they are being closed with various jQuery effects.

Getting ready

To get acquainted with the alert component of the Bootstrap 4 framework, refer to the official documentation at https://v4-alpha.getbootstrap.com/components/alerts/.

Note

A quick tip regarding code formatting on Cloud9 IDE: There is a simple solution for users to format code in Cloud9 IDE. The user should align all the copy/pasted code to the left...

Making full-page modals


In this recipe, we will alter the behavior of the modal component, so as to have it completely cover the available screen space.

To see the final result, open the chapter4/complete code's app folder, and run the git bash on it. Follow it up with the harp server command, and navigate to localhost:9000 in your browser to see the result we will achieve in this recipe.

Upon opening the web page as explained in the preceding paragraph, you should see a large Click Me button that will trigger the modal, which will then appear and cover the entire viewport.

Getting ready

To get acquainted with the modal component in Bootstrap 4, visit https://v4-alpha.getbootstrap.com/components/modal/.

How to do it…

  1. Open the empty recipe-04-02.ejs file, located in the chapter4/start/app folder.
  2. Add the following code to it:
<div class="container">

 <div class="mt-5">
 <h1><%- title %></h1>
 <p><a href="https://v4-alpha.getbootstrap.com/components/modal...

Altering the behavior of popups using tether options


In this recipe, we will alter the pop-up component so that it can be dismissed by clicking anywhere on the page.

To see the final result, open the chapter4/complete code's app folder, and run the git bash on it. Follow it up with the harp server command, and navigate to localhost:9000 in your browser to see the result we will achieve in this recipe.

Upon opening the web page as explained in the previous paragraph, you should see a large Dismissible popover button. Clicking on the button will make the popover appear. Clicking again (anywhere on the page) will close the popover.

Getting ready

To get acquainted with the popover component in Bootstrap 4, visit https://v4-alpha.getbootstrap.com/components/popovers/. Also, visit http://tether.io/ for additional information, as popovers rely on this third-party library to work.

Test the default behavior of the popover component by checking out the live demo section at https://v4-alpha.getbootstrap...

Controlling the color and opacity of ToolTips using Sass variables


In this recipe, we will change the ToolTip component so that it has a different color, as well as a different opacity, from what we have in the default options.

To see the final result, open the chapter4/complete code's app folder, and run the git bash on it. Follow it up with the harp server command, and navigate to localhost:9000 in your browser to see the result we will achieve in this recipe.

Upon opening the web page as explained in the previous paragraph, you should see four buttons. Hovering over each of the buttons will trigger ToolTips in four different directions.

Getting ready

To get started with the ToolTip component in Bootstrap 4, visit https://v4-alpha.getbootstrap.com/components/ToolTips/. Also, visit http://tether.io/ for additional information, as ToolTips relies on this third-party library to work.

Test the default behavior of the ToolTip component by checking out the interactive demo section at https://v4...

Using Bootstrap's Sass mixins to create custom buttons


To create custom buttons, we will use Bootstrap's Sass mixins in this recipe.

To see the final result, open the chapter4completed code's app folder, and run the git bash on it. Follow it up with the harp server command, and navigate to localhost:9000 in your browser to see the result we will achieve in this recipe.

Upon opening the web page as explained in the preceding paragraph, you should see six fully functional custom buttons at the bottom of the page.

Getting ready

To get started with the custom buttons in Bootstrap 4, first visit the official documentation on the buttons component in Bootstrap 4, available at https://v4-alpha.getbootstrap.com/components/buttons/.

Default buttons are showcased at https://v4-alpha.getbootstrap.com/components/buttons/#examples. Bootstrap 4 also introduces outline buttons. To see them in practice, navigate to https://v4-alpha.getbootstrap.com/components/buttons/#outline-buttons.

How to do it…

  1. Open the...

Adjusting the rounding of corners on buttons and button groups


There are several components that this recipe can be used on. The official documentation for these components is available at https://v4-alpha.getbootstrap.com/components/buttons/, https://v4-alpha.getbootstrap.com/components/button-group/, https://v4-alpha.getbootstrap.com/components/dropdowns/, and https://v4-alpha.getbootstrap.com/components/pagination/.

Getting ready

To make this recipe work, you will need to include the SCSS code from the preceding recipe. The reason for this is that the previous recipe already specifies the custom button classes used in this recipe too (classes of btn-tomato, btn-green, and btn-purple).

An alternative approach would be to use Bootstrap's default buttons, but if you choose to do it this way, bear in mind that you will need to change the references to btn-tomato, btn-green, and btn-purple in the following code to any of the default Bootstrap button classes, such as btn-primary, btn-info, and...

Controlling the number of card columns on different breakpoints with SCSS


This recipe will involve some SCSS mixins, which will alter the behavior of the card-columns component. To be able to showcase the desired effect, we will have to have a few hundred lines of compiled HTML code. This poses an issue; how do we show all that code inside a recipe? Here, Harp partials come to the rescue! Since most of the code in this recipe is repetitive, we will make a separate file. The file will contain the code needed to make a single card. Then, we will have a div with the class of card-columns, and this div will hold 20 cards, which will, in fact, be 20 calls to the single card file in our source code before compilation. This will make it easy for us to showcase how the number of cards in this card-columns div will change, based on screen width. To see the final result, open the chapter4/complete code's app folder, and run the console (that is, bash) on it. Follow it up with the harp server command...

Making cards responsive


This recipe is closely connected with the preceding one. To show how to make cards responsive, we will use the preceding recipe's single card include.

To see the final result, open the chapter4/complete code's app folder, and run the git bash on it. Follow it up with the harp server command, and navigate to localhost:9000 in your browser to see the result we will achieve in this recipe.

Upon opening the web page as explained in the previous paragraph, you should see two rows of cards in two card decks. The container that holds them is styled with the .container-fluid class. Open the dev tools with F12 and drag its edge from right to left to see the decks respond to the change of the viewport.

Getting ready

To get acquainted with how card decks work, navigate to the card decks section of the Bootstrap documentation at https://v4-alpha.getbootstrap.com/components/card/#card-decks.

How to do it…

  1. Open the currently empty file located at chapter4/start/app/recipe04-08.ejs,...

Easily positioning inline forms


In this recipe, we will position an inline form in the center of the viewport, on the left, and on the right. To achieve that, we will be using flexbox classes of justify-content-center, justify-content-start, and justify-content-end.

Getting ready

To get acquainted with how forms work, navigate to the forms component section of the Bootstrap documentation at https://v4-alpha.getbootstrap.com/components/forms/.

How to do it…

  1. Open the currently empty file located at chapter4/start/app/recipe04-09.ejs, and add the following code:
<div class="container-fluid">

 <div class="mt-5">
 <h1><%- title %></h1>
 <p><a href="https://v4-alpha.getbootstrap.com/components/forms/" 
   target="_blank">Link to bootstrap forms docs</a></p>
 </div>

</div><!-- /.container --> 
  1. In the same file, add the following code to the bottom to position the first form in the center:
<div class="container-fluid mt-5">...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Bootstrap 4 Cookbook
Published in: Jun 2017Publisher: PacktISBN-13: 9781785889295
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ajdin Imsirovic

Ajdin Imsirovic is a full-stack web developer who has published several courses on the subject of web design and web development. He has also authored three books, Bootstrap 4 Cookbook, Elm Web Development, and Vue.js Quick Start Guide. In his fourth book, Vue CLI 3 Quick Start Guide, he introduces readers to the rich ecosystem of frontend tooling and best practices.
Read more about Ajdin Imsirovic