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

Chapter 7. Extending Bootstrap with JavaScript Plugins

In this chapter, we're going to dive deeper into Bootstrap components by learning how to extend the framework using JavaScript plugins. You may remember that back in the first chapter we included bootstrap.min.js in our template. This file contains a number of JavaScript components that come with Bootstrap. In this chapter, we'll go over how to use some of these components, including: Modals, Tooltips, Popovers, Collapse, and Carousel. Let's get right to it by learning how to create a Modal in Bootstrap 4.

Coding a Modal dialog

Modals go by a number of different names; you may also know them as dialogs, popups, overlays, or alerts. In the case of Bootstrap, this component is referred to as a Modal and that is how I'll be referring to it throughout the book. A Modal is made up of two required pieces of code. The first is a button, and here's the basic code required to render it:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#firstModal"> 
  Open Modal 
</button> 

As you can see, this is a basic Button component with a few attributes added to it:

  • The first is the data-toggle data attribute, which needs to be set to modal. This tells the browser that this <button> is attached to a Modal component.
  • The second is the data-target attribute, which should be an ID. It doesn't really matter what you name this, I've called it #firstModal. It's important to note this ID name as it will be tied in later. Also make sure that the ID name is unique.

Once you've coded this up, it should look like a regular button in the browser:

Coding a Modal dialog

Coding the Modal dialog

The second part of the Modal component is the dialog. This is the part that will pop up in the browser once you click the button. Let's take a look at some basic code for creating the dialog:

<div class="modal fade" id="firstModal" tabindex="-1" role="dialog" aria-hidden="true"> 
  <div class="modal-dialog" role="document"> 
    <div class="modal-content"> 
      <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"> 
          <span aria-hidden="true">&times;</span> 
        </button> 
        <h4 class="modal-title">Dialog Title</h4> 
      </div> 
      <div class="modal-body"> 
        Some copy for your modal. 
      </div> 
      <div class="modal-footer"> 
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> 
        <button type="button" class="btn btn-primary">Save</button> 
      </div> 
    </div> 
  </div> 
</div> 

This is a bigger piece of code and there are a few things going on here that I need to explain to you:

  • The entire dialog is wrapped in a <div> with a required class of .modal. There's also an optional .fade class there, which will fade the dialog in. Note the ID on this <div> because it's important. The ID value needs to match the data-target attribute you set on the button. This is how we tell the browser to link that button with this dialog. Finally, there are a couple of other attributes that are required by Bootstrap including tabindex, role, and aria-hidden. Make sure you include those with their corresponding values.
  • Inside the first <div> we have a second one with a class of .modal-dialog on it; make sure you include that.
  • Next, the interior of the Modal is split into three parts: header, body, and footer.
  • Inside our .modal-dialog, add another <div> with a class of .modal-header on it. Within this section you'll notice another button. This button is the Close or X icon for the Modal; although not required, it's a good idea to include this.
  • After the button you need to include a header tag, in this case a <h4>, with a CSS class of .modal-title on it. Here you should enter the title for your Modal.
  • The next section is another <div> for our body and it has a class of .modal-body on it. Within this section you should enter the body copy for your Modal.
  • Finally, we have the footer section, which is another <div> with a class of .modal-footer on it. Inside this section you'll find two buttons that you need to include. The first is the white button labeled Close which when clicked will close the Modal. Note that the <button> tag has a data attribute called data-dismiss on it and its value is modal. This will close the Modal. The second button is a primary button that would be used as a Save button if you were hooking in the actual functionality.

After coding all that up, go to the browser and click on your button. You should then see a Modal that looks like this:

Coding the Modal dialog

As you can see, our Modal has popped up over the button. You can read the Modal title and body and see the footer buttons as well as the Close or X button in the top-right corner. You may have noticed that you didn't actually have to write any JavaScript to make this Modal work. That is the power of the Bootstrap framework; all of the JavaScript is already written for you and you can simply call the Modal functionality by using the HTML data attributes, which makes things much easier. That concludes the lesson on Modals; next let's move on to learning how to use Tooltips.