Table of Contents for
Bootstrap 4 – Responsive Web Design

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Bootstrap 4 – Responsive Web Design by Jason Marah Published by Packt Publishing, 2017
  1. Cover
  2. Table of Contents
  3. Bootstrap 4 – Responsive Web Design
  4. Bootstrap 4 – Responsive Web Design
  5. Credits
  6. Preface
  7. What you need for this learning path
  8. Who this learning path is for
  9. Reader feedback
  10. Customer support
  11. 1. Module 1
  12. 1. Getting Started
  13. Setting up the framework
  14. Building our first Bootstrap example
  15. Optionally using the CDN setup
  16. Community activity
  17. Bootstrap and web applications
  18. Browser compatibility
  19. Summary
  20. 2. Creating a Solid Scaffolding
  21. Building our scaffolding
  22. Fluid container
  23. We need some style!
  24. Manipulating tables
  25. Like a boss!
  26. Final thoughts
  27. Summary
  28. 3. Yes, You Should Go Mobile First
  29. Bootstrap and the mobile-first design
  30. How to debug different viewports at the browser
  31. Cleaning up the mess
  32. Creating the landing page for different devices
  33. Summary
  34. 4. Applying the Bootstrap Style
  35. Summary
  36. 5. Making It Fancy
  37. Paying attention to your navigation
  38. Dropping it down
  39. Making an input grouping
  40. Getting ready for flexbox!
  41. Summary
  42. 6. Can You Build a Web App?
  43. Adding the navigation
  44. Do a grid again
  45. Playing the cards
  46. Implementing the main content
  47. Creating breadcrumbs
  48. Finishing with the right-hand-side content
  49. Summary
  50. 7. Of Course, You Can Build a Web App!
  51. Waiting for the progress bar
  52. Creating a settings page
  53. Summary
  54. 8. Working with JavaScript
  55. Awesome Bootstrap modals
  56. Creating our custom modal
  57. A tool for your tip
  58. Pop it all over
  59. Making the menu affix
  60. Finishing the web app
  61. Summary
  62. 9. Entering in the Advanced Mode
  63. The last navigation bar with flexbox
  64. Filling the main fluid content
  65. Filling the main content
  66. Overhead loading
  67. Fixing the toggle button for mobile
  68. Summary
  69. 10. Bringing Components to Life
  70. Fixing the mobile viewport
  71. Learning more advanced plugins
  72. Summary
  73. 11. Making It Your Taste
  74. Working with plugin customization
  75. The additional Bootstrap plugins
  76. Creating our Bootstrap plugin
  77. Defining the plugin methods
  78. Creating additional plugin methods
  79. Summary
  80. 2. Module 2
  81. 1. Introducing Bootstrap 4
  82. Summary
  83. 2. Using Bootstrap Build Tools
  84. Download the Bootstrap source files
  85. Setting up the blog project
  86. Setting up the JSON files
  87. Creating our first page template
  88. Summary
  89. 3. Jumping into Flexbox
  90. Ordering your Flexbox
  91. Wrapping your Flexbox
  92. Setting up the Bootstrap Flexbox layout grid
  93. Setting up a Flexbox project
  94. Designing a single blog post
  95. Summary
  96. 4. Working with Layouts
  97. Inserting rows into your layout
  98. Adding columns to your layout
  99. Choosing a column class
  100. Creating a simple three-column layout
  101. Mixing column classes for different devices
  102. Coding the blog home page
  103. Using responsive utility classes
  104. Summary
  105. 5. Working with Content
  106. Learning to use typography
  107. Customizing headings
  108. How to style images
  109. Coding tables
  110. Summary
  111. 6. Playing with Components
  112. Basic button examples
  113. Creating outlined buttons
  114. Checkbox and radio buttons
  115. Coding forms in Bootstrap 4
  116. Creating an inline form
  117. Adding validation to inputs
  118. Using the Jumbotron component
  119. Adding the Label component
  120. Using the Alerts component
  121. Using Cards for layout
  122. Updating the Blog index page
  123. How to use the Navs component
  124. Adding Breadcrumbs to a page
  125. Using the Pagination component
  126. How to use the List Group component
  127. Summary
  128. 7. Extending Bootstrap with JavaScript Plugins
  129. Coding Tooltips
  130. Avoiding collisions with our components
  131. Using Popover components
  132. Using the Collapse component
  133. Coding an Accordion with the Collapse component
  134. Coding a Bootstrap Carousel
  135. Summary
  136. 8. Throwing in Some Sass
  137. Using Sass in the blog project
  138. Importing partials in Sass
  139. Creating a collection of variables
  140. Customizing components
  141. Writing a theme
  142. Summary
  143. 9. Migrating from Version 3
  144. Big changes in version 4
  145. Updating your variables
  146. Additional global changes
  147. Other font updates
  148. Migrating components
  149. Migrating JavaScript
  150. Miscellaneous migration changes
  151. Summary
  152. 3. Module 3
  153. 1. Revving Up Bootstrap
  154. What Bootstrap 4 Alpha 4 has to offer
  155. Setting up our project
  156. Summary
  157. 2. Making a Style Statement
  158. Image elements
  159. Responsive utilities
  160. Helper classes
  161. Text alignment and transformation
  162. Summary
  163. 3. Building the Layout
  164. Adding Bootstrap components
  165. Summary
  166. 4. On Navigation, Footers, Alerts, and Content
  167. Improving navigation using Scrollspy
  168. Customizing scroll speed
  169. Icons
  170. Using and customizing alerts
  171. Creating a footer
  172. Creating and customizing forms
  173. Form validation
  174. Progress indicators
  175. Adding content using media objects
  176. Figures
  177. Quotes
  178. Abbreviations
  179. Summary
  180. 5. Speeding Up Development Using jQuery Plugins
  181. Enhanced pagination using bootpag
  182. Displaying images using Bootstrap Lightbox
  183. Improving our price list with DataTables
  184. Summary
  185. 6. Customizing Your Plugins
  186. Customizing plugins
  187. Writing a custom Bootstrap jQuery plugin
  188. Summary
  189. 7. Integrating Bootstrap with Third-Party Plugins
  190. Hover
  191. Summary
  192. 8. Optimizing Your Website
  193. Minifying CSS and JavaScript
  194. Introducing Grunt
  195. Running tasks automatically
  196. Stripping our website of unused CSS
  197. JavaScript file concatenation
  198. Summary
  199. 9. Integrating with AngularJS and React
  200. Introducing React
  201. Summary
  202. Bibliography
  203. Index

Hover

Hover, http://ianlunn.github.io/Hover/, is a neat, pure CSS library that provides transition effects. Adhering to the "Do one thing, do one thing well" approach, Hover only concerns itself with hover transitions, as you may have guessed from the name. Hover comes baked in with a huge array of transitions and provides easy integration with CSS, Less, and Sass.

Hover breaks these transitions into seven distinct groups:

  • 2D transitons
  • Background transitions
  • Icons, by leveraging Font Awesome icons
  • Border transitons
  • Shadow and glow transitions, simulating 3D transitions
  • Speech bubbles
  • Curls

Throughout this section, we will touch on a number of these different groups. An extensive list of the transitions is available on the Hover website. Before we get to that, let's add Hover to MyPhoto.

Adding Hover to MyPhoto

Add Hover to MyPhoto via Bower:

    bower install Hover

Within the bower_components directory, there should now be a Hover directory. We will reference the minified CSS straight into our markup. Add the following link tag in the head of the MyPhoto HTML, below the existing CSS references:

    <link rel="stylesheet" href="bower_components/Hover/css/
    hover-min.css" />

Let's add a Hover transition to make sure everything is in working order.

Making the navbar grow

As a quick test to make sure we have completed setting up of Hover correctly, let's apply some Hover transitions to the MyPhoto navbar.

Using Hover transitions is even simpler than Animate.css. We simply add one class to the element, and voila, a Hover transition is applied. As you will notice, all Hover classes are prefixed with hvr - to help avoid conflicts with other style sheets on the page.

We're going to spice up our nav - link links with one of the border transitions from Hover: hvr - underline - from - center . The hvr -underline-from-center class renders an underline on a given element, which grows from the center of the element. Let's add this to our five nav - link links:

    <ul class="nav nav-pills">
        <li class="nav-item"><a class="nav-link hvr-underline-from-
        center" href="#welcome">Welcome</a></li>
        <li class="nav-item"><a class="nav-link hvr-underline-from-
        center" href="#services">Services</a></li>
        <li class="nav-item"><a class="nav-link hvr-underline-from-
        center" href="#gallery">Gallery</a></li>
        <li class="nav-item"><a class="nav-link hvr-underline-from-
        center" href="#about">About</a></li>
        <li class="nav-item"><a class="nav-link hvr-underline-from-
        center" href="#contact">Contact Us</a></li>
        <li class="nav-item dropdown pull-xs-right">
            ... 
        </li>
    </ul>

Take a look at the following screenshot:

Making the navbar grow

Figure 7.10: A border transition temporarily added to our navigation menu items. As the user hovers over one of the navigation links, they receive a clear visual cue.

Now, when a user hovers on one of our navigation links, they get a nice indicator providing a clear visual aid.

Awesome Hover icons

As previously mentioned, Hover has a range of icon effects. Hover leverages the Font Awesome library, to render icons, which Hover then animates. Hover provides a range of different effects, but each effect actually only applies to one icon. All these effects are prefixed with hvr - icon - <effect name> . Open bower_components/hover/css/hover.css and check out the hvr - icon - bob:before class:

    .hvr-icon-bob:before {
        content: "\f077";        position : absolute;
        right: 1em;
        padding: 0 1px;
        font-family: FontAwesome;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }

Using the pseudo-selector before , hvr - icon - bob is creating an element with content: \f077 , which relates to the icon specified by that id in Font Awesome, as the font - family is set to FontAwesome . Taking a look at FontAwesome.css , we can see that \f077 represents the fa - chevron - up class. As you can see, the icon is hardcoded into the class, so we can only ever use hvr - icon - bob with the upward chevron icon, unless we override the content rule of that class. The transform properties with the value of translateZ( 0 ) are used to make the transition smoother, as it creates a new stacking context. The new stacking context forces rendering of the animation to the GPU, creating a smoother transition.

Let's see hvr-icon-bob in action by updating the Profile drop-down button, replacing the caret class with the hvr-icon-bob class. Replace the Profile button markup with the following:

    <a href="#" class="nav-link" data-toggle="dropdown" role="button"
        aria-haspopup="true" aria-expanded="false">
        <span class="hvr-icon-bob">Profile</span>
    </a>

Take a look at the following screenshot:

Awesome Hover icons

Figure 7.11: An inverted chevron that moves up and down as the user hovers over it

When a user hovers over the icon, the icon will animate up and down. Great! Well, except that it is upside down and misaligned. Let's fix that. In myphoto.css , we will override the content property of hvr-icon-bob with \f078 , which is the fa-chevron-down class, and we will vertically align it correctly:

    .hvr-icon-bob :before {
        content: "\f078";
    }
    .hvr-icon-bob {

        vertical-align: top;
    }

We also need to ensure that myphoto.css is loaded after Hover:

    <link rel="stylesheet" href="bower_components/bootstrap/dist/css
    /bootstrap.min.css" />
    <link rel="stylesheet" href="bower_components/Hover/css/hover-min.css"
    />

Take a look at the following screenshot:

Awesome Hover icons

Figure 7.12: An animated chevron facing down

Better! However, this approach can easily become a maintenance nightmare. There are other approaches to managing Hover icon classes so they're more usable. For instance, we could use specific classes to determine which icon to display. Add the . myphoto - chevron - down selector to the hvr - icon - bob:before rule in myphoto.css :

    .myphoto-chevron-down.hvr-icon-bob:before {
        content: "\f078";
    }

Refresh the page, and the upwards chevron will be displayed again.

But, if we add the myphoto - chevron - down class to the element, the downward chevron will be rendered:

    <span class="myphoto-chevron-down hvr-icon-bob">Profile</span>

The approach described here makes using the Hover icon animations far more maintainable, and adds much more context than just using hvr - icon - bob , which just describes the animation and not the icon. We could also simply use the actual FontAwesome classes to describe the behavior, but Font Awesome also provides display rules that may not be in line with how Hover designed these classes to work.

Salvattore Hover

We can also use Hover to improve a user's interaction with our Salvattore-powered testimonials component. The testimonials component already leverages Animate.css to add an interesting transition when rendering the grid, but we can use Hover to add an interesting transition when a user actually interacts with it.

The grid is quite flat and fails to grab the user's attention once loaded. The individual columns also fail to gain focus. To solve this, we can use Hover to increase the size of the column when a user hovers on the column. One of the classes provided by Hover is hvr-grow-shadow , which adds a hover state to an element that expands the column and adds a drop-shadow, but doesn't affect the other columns or rows within the grid. All we need to do here is add hvr-grow-shadow to each testimonial column:

    <div class="myphoto-testimonial-grid animated fadeIn" data-columns>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Debbie</h6>
            <p>Great service! Would recommend to friends!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Anne</h6>
            <p>Really high quality prints!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Oscar</h6>
            <p>Declared their greatness, exhibited greatness.</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Joey</h6>
            <p>5 stars! Thanks for the great photos!</p>
        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Mary</h6>
            <p>Made a stressful event much easier! Absolute
            professionals!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Alice</h6>
            <p>Wonderful! Exactly as I imagined they would turn out!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Jack & Jill</h6>
            <p>So happy with how the photos turned out! Thanks for 
            capturing the memories of our day!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Nick</h6>
            <p>Perfectly captured the mood of our gig. Top notch.</p>
        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow">
            <h6>Tony</h6>
            <p>Captured our Cup final win! Great stuff!</p>

        </div>
    </div>

Take a look at the following screenshot:

Salvattore Hover

Figure 7.13: After applying the hvr-grow-shadow class, hovering over an individual testimonial will cause it to "grow" without effecting the rest of the grid

Now, when a user hovers over a column, the individual column grows, without affecting the rest of the grid. One of the cool things about Hover is that all the classes play nicely with each other, following the cascading nature of CSS. No JavaScript magic, just pure CSS. To see an example of this, we will add another Hover class. This one is from the range of Hover background transition classes, hvr - sweep - to - top . The hvr - sweep - to - top class animates a change in the background color with a fill effect from the bottom to the top. Let's add hvr - sweep - to - top to the testimonial columns:

    <div class="myphoto-testimonial-grid animated fadeIn" data-columns>
        <div class="myphoto-testimonial-column hvr-grow-shadow
        hvr-sweep-to-top">
            <h6>Debbie</h6>
            <p>Great service! Would recommend to friends!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow
        hvr-sweep-to-top">
            <h6>Anne</h6>
            <p>Really high quality prints!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow 
        hvr-sweep-to-top">
            <h6>Oscar</h6>
            <p>Declared their greatness, exhibited greatness.</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow 
        hvr-sweep-to-top">
            <h6>Joey</h6>
            <p>5 stars! Thanks for the great photos!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow 
        hvr-sweep-to-top">
            <h6>Mary</h6>
            <p>Made a stressful event much easier! Absolute
            professionals!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow
        hvr-sweep-to-top">
            <h6>Alice</h6>
            <p>Wonderful! Exactly as I imagined they would turn out!</p>

        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow 
        hvr-sweep-to-top">
            <h6>Jack & Jill</h6>
            <p>So happy with how the photos turned out! Thanks for
            capturing the memories of our day!</p>
        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow 
        hvr-sweep-to-top">
            <h6>Nick</h6>
            <p>Perfectly captured the mood of our gig. Top notch.</p>
        </div>
        <div class="myphoto-testimonial-column hvr-grow-shadow 
        hvr-sweep-to-top">
            <h6>Tony</h6>
            <p>Captured our Cup final win! Great stuff!</p>

        </div>
    </div>

Take a look at the following screenshot:

Salvattore Hover

Figure 7.14: After applying the hvr-grow-shadow and hvr-sweep-to-top classes, hovering over an individual testimonial will cause it to "grow" and change color

Now we have both the expanded columns, with a drop-shadow, along with the fill effect provided by the hvr - sweep - to - top class. As we have seen, Hover provides very simple to use but very elegant transitions to add an extra layer of interaction for users. Being pure CSS, Hover is also exceedingly simple to integrate with most libraries and frameworks.