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

Importing partials in Sass

Just as you can do in Harp.js, you can use partials in Sass. If you've forgotten what a partial is, it's a little snippet of code that is saved into a different file and then imported into the main CSS theme or layout, in the case of Harp. This can be handy for making your CSS modular and easier to manage. For example, it would make a ton of sense to break every Bootstrap component into its own CSS file and then use the @import directive to bring them all into a single master theme, which is then included in your project. Let's go over an example of how you could do this for a single component. In your project, go to the /css directory and create a new sub-folder called /components. The the full path should be:

/css/components 

In the /components directory, create a new Sass file and name it _buttons.scss. Make sure you always insert an underscore at the start of the filename of a partial. The compiler will then ignore these files as the underscore means it is being inserted into another file. Enter the following at the top of the file as a marker:

/* buttons */ 

Save the buttons file and then open up custom.scss and add the following line of code to the file:

@import "components/_buttons.scss"; 

That line of code uses the @import rule, which will allow us to import the _buttons.scss file into our main theme file that we are calling custom.scss. As I've mentioned, the reason you need to do this is for maintainability. This makes the code much easier to read and to add/remove components, which is just another way of saying it makes it more modular.

Before we can test this out to make sure it works, we need to add some code to our _buttons.scss file. Let's add some simple CSS to change the primary button as an example:

.btn-primary { 
  background-color: green; 
} 

After adding this code, save the file and do a harp compile. Then launch the server and check out the home page; the buttons will be green like this:

Importing partials in Sass

After testing that out, you may want to take that custom code out unless you want the buttons to remain green. That's just a simple example of how you can use partials to make your Bootstrap components more modular. I'll get into that topic in greater depth in a future chapter but for now we are going to focus on using Sass mixins.

Using mixins

Writing something in CSS, such as, for example, browser vendor prefixes, can be really tedious. Mixins allow you to group CSS declarations together so that you can reuse them through your project. This is a great because you can include the code for, say, a border-radius, using one line of code instead of multiple lines for each browser. To start, open up custom.scss and insert the following code at the top of the file:

@mixin border-radius($radius) { 
  -webkit-border-radius: $radius; 
     -moz-border-radius: $radius; 
      -ms-border-radius: $radius; 
          border-radius: $radius; 
} 

Let's go over a few things that are happening here:

  • A mixin is always started in Sass with the @mixin keyword
  • Following that, you want to include the property name to target as well as set a variable, in this case $radius
  • We then apply the $radius variable to each browser prefix instance

We've set up the mixin to handle the border-radius property but we still need to add the corner value to an element. Let's change the border-radius value for the default Bootstrap button. Open up _buttons.scss and insert the following code:

.btn { 
  @include border-radius(20px); 
 } 

Let me explain what is happening here:

  • I'm targeting all Bootstrap buttons by inserting the .btn class
  • Inserting the @include keyword will grab the border-radius mixin
  • Lastly, I've provided a value of 20px, which will make our buttons look really rounded on each end

Save your file, run the harp compile command, and then, when you view the project in the browser, it should look like this:

Using mixins

That concludes a fairly simple example of how to use mixins in Bootstrap 4. You can use them for many other reasons but replacing CSS3 vendor prefixes is one of the most common and useful. Next we'll cover a slightly more complicated topic in Sass, which is the use of operators.

How to use operators

Sass allows you to perform basic math operations in CSS, which is useful for a number of reasons. First of all, you can use the following operators +, -, *, /, and %. To give you an understanding of how you can use operators in CSS, let's learn how to convert a pixel-based grid into percentages. We'll create two columns in pixels and then use some Sass to convert them to percentages. Open up custom.scss and insert the following code:

.left-column { 
  width: 700px / 1000px * 100%; 
} 
 
.right-column { 
  width: 300px / 1000px * 100%; 
} 

Now, I've created two columns here. The .left-column class will have a width of 70% after we compile this Sass operator. The .right-column class will have a width of 30%. So if we add those together we'll get roughly a three-quarter layout with a larger column on the left and a smaller column on the right. Run a harp compile command to build this code and then open up custom.css in the /www/css folder. There you should find the following code:

.left-column { 
  width:70%; 
} 
 
.right-column { 
  width:30%; 
} 

As you can see, our Sass operators have been converted into regular percentage values. That's just one way you can use operators in Sass; I'd encourage you to play around more with them. Next we're going to learn how to set up a library of Sass variables that you can use to create a Bootstrap theme.