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

Creating an inline form

Let's start by learning how to create an inline form. This is a layout you might want to use in the header of a project or perhaps for a login page. In this case, we're going to align the fields and buttons of the form vertically across the page. For this example, let's create a simple login form with the following code:

<form class="form-inline"> 
  <div class="form-group"> 
    <label>Name</label> 
    <input type="text" class="form-control" placeholder="Mike Smith"> 
  </div> 
  <div class="form-group"> 
    <label>Email</label> 
    <input type="email" class="form-control" placeholder="mike@gmail.com"> 
  </div> 
  <button type="submit" class="btn btn-primary">Login</button> 
</form> 

There are a few things going on in this form, so let me explain them for you:

  • For inline forms, we need to add a CSS class named .form-inline to the <form> tag.
  • You'll also notice the <fieldset> tags have been replaced with <div> tags. This is so they can be set to display as inline-block, which won't work with a fieldset.

Aside from those two differences, the form is coded up the same way as a regular one. Once you're done, your form should look like this in the browser:

Creating an inline form

If you're like me, you might find the labels next to the text inputs kind of ugly. The good news is there is an easy way to hide them.

Hiding the labels in an inline form

The reason those labels are there is for accessibility and screen readers. We don't want to remove them altogether from the code, but we can hide them by adding a CSS class named .sr-only. This class stands for screen reader only and will therefore only show the labels if they are viewed on an accessible screen reader. Here is an example of how to add the CSS class:

<label class="sr-only">Name</label> 

After you apply that CSS class to all the labels in the form, it should now appear like this in the browser:

Hiding the labels in an inline form

That concludes how to make a basic inline form. However, what if you want to include other fields in an inline manner? Let's see how we can add checkboxes and radios.

Adding inline checkboxes and radio buttons

If you'd like to include checkboxes and radio buttons to an inline form you need to make some changes to your code. Let's start by going over the checkbox code. Insert the following code after the last text input in the inline form:

<label class="checkbox-inline"> 
  <input type="checkbox" value="option1"> Remember me? 
</label> 

There are a couple of things here that you need to be aware of:

  • First, there is no longer a <div> wrapped around the checkbox
  • You need to add a class named .checkbox-inline to the checkbox's <label> tag

Once you do this, save your form and it should look like this in the browser:

Adding inline checkboxes and radio buttons

Now that we've added the checkbox, let's check out an example using radio buttons. Add the following code to your form after the checkbox code:

<label class="radio-inline"> 
  <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> Yes 
</label> 
<label class="radio-inline"> 
  <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2"> No 
</label> 

As you can see, the pattern here is exactly the same. The <div> around each radio button has been removed. Instead, there is a CSS class named .radio-inline that needs to be added to each radio <label> tag. Once you've completed this step, your form should look like this:

Adding inline checkboxes and radio buttons

That completes everything you need to know about inline forms. Let's now move on to some more utility-type actions that you can apply to your form fields.

Changing the size of inputs

Bootstrap comes with a few handy utility CSS classes that you can use with form fields to have them appear at different sizes. Along with the default size, you can choose to display your fields in a larger or smaller size. Let's take a look at the code to render all three size variations:

<input class="form-control form-control-lg" type="text" placeholder="form-control-lg"> 
<input class="form-control" type="text" placeholder="Default input, No class required"> 
<input class="form-control form-control-sm" type="text" placeholder="form-control-sm"> 

To use the different size inputs, you simply have to add an additional class to the tag:

  • For a larger input, use the class .form-control-lg
  • For a smaller input, use the class .form-control-sm
  • The default input size requires no extra CSS class

Here's how each version looks in the browser:

Changing the size of inputs

As you can see, the larger input is taller and has some additional padding. The smaller input is shorter with reduced padding. These classes only cover the vertical size of an input. Now let's learn how to control the width of inputs.

Controlling the width of form fields

Since Bootstrap is a mobile-first framework, form fields are designed to stretch to fit the width of their column. Therefore, if you are using .col-md-12 for your column class, the field is going to stretch to the width of the layout. This may not always be what you want, you may only want the input to stretch to half of the width of the layout.

If this is the case, you need to wrap your field in a <div> with a column class on it to control the width. Let's check out some example code to get the point across:

<div class="col-md-12"> 
    <input type="text" class="form-control" placeholder="full width"> 
</div> 
<div class="col-md-6"> 
    <input type="text" class="form-control" placeholder="half width"> 
</div> 

In the preceding code, I've removed some of the labels and other form code to make it easier to see what is going on. Here's a breakdown of what you need to know:

  • You need to wrap your input in a <div> with a column class on it
  • The first input will stretch to the width of the layout because of the .col-md-12 class
  • The second input will only stretch to fill 50% of the layout because of the .col-md-6 class

Let's take a look at how this will look in the actual browser:

Controlling the width of form fields

As you can see, the second input only stretches to half of the width. This is how you can control the width of inputs if you don't want them to fill the entire layout of your page. The last thing I'd like to cover when it comes to forms is validation of input fields.