Bootstrap 4 Cookbook
eBook - ePub

Bootstrap 4 Cookbook

  1. 338 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Bootstrap 4 Cookbook

About this book

Take your Bootstrap game to the next level with this practical guideAbout This Book• Packed with easy-to-follow recipes on building responsive web pages with Bootstrap 4 that can be applied to a web project of your choice• Build intuitive user interfaces that are mobile-ready with the latest features offered by BS4• Stay on top of the changes that Bootstrap 4 brings to front-end development• Craft beautiful UIs and learn best practices, tips and tricks for quick, effortless, and proper Bootstrap 4 developmentWho This Book Is ForIf you are a web designer or a developer who is familiar with the basics of Bootstrap and now want to build highly responsive and professional web pages using Bootstrap 4, this cookbook is for you. Familiarity with the fundamentals of HTML, CSS and jQuery, and some experience of incorporating JavaScript plugins is assumed. What You Will Learn• Craft beautiful UIs the right way• Use jQuery and JavaScript to extend Bootstrap layouts• Become more efficient by speeding up your workflow to achieve amazing results in the shortest time possible• Setup your environment for future changes of the framework.• Stay DRY by quickly prototyping Bootstrap-based websites with the help of Github's own serverless blogging platform, Jekyll• Integrate Bootstrap with the most popular JS frameworks, Angular and React• Combine Bootstrap with the.NET platformIn DetailBootstrap, one of the most popular front-end frameworks, is perfectly built to design elegant, powerful, and responsive interfaces for professional-level web pages. It supports responsive design by dynamically adjusting your web page layout.Bootstrap 4 is a major update with many impressive changes that greatly enhance the end results produced by Bootstrap. This cookbook is a collection of great recipes that show you how to use all the latest features of Bootstrap to build compelling UIs.This book is using the most up-to-date version of Bootstrap 4 in all its chapters. First off, you will be shown how you can leverage the latest core features of Bootstrap 4 to create stunning web pages and responsive media. You will gradually move on to extending Bootstrap 4 with the help of plugins to build highly customized and powerful UIs.By the end of this book, you will know how to leverage, extend, and integrate bootstrap to achieve optimal results for your web projects.Style and approachPacked full of solutions that can be instantly applied, the practical-based recipes will help you get the most from Bootstrap.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Bootstrap 4 Cookbook by Ajdin Imsirovic in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in JavaScript. We have over one million books available in our catalogue for you to explore.

Extending Bootstrap 4

In this chapter, we will cover the following topics:
  • Converting checkboxes into Toggles with Bootstrap Toggle plugin
  • Onboarding users with Shepherd
  • Toggling visibility of password fields with custom jQuery code
  • Extending the functionality of select elements with Bootstrap Select plugin
  • Customizing select boxes with Select2 plugin
  • Adding input sliders with Rangeslider.js
  • Allowing users to easily add dates to your input fields with jQuery UI Datepicker
  • Converting plain tables into sophisticated data tables with Bootgrid
  • Navigating easily with simple-sidebar jQuery plugin
  • Adding fully customizable notifications with Notify.js
  • Integrating a fancy modal using animatedModal.js
  • Making pagination dynamic with the jQuery Pagination plugin and simplePagination.js
  • Validating forms with svalidate.js
  • Adding a rating system using jQuery Bar Rating plugin

Introduction

In this chapter, we will look at a variety of jQuery plugins we can use to extend Bootstrap 4. Some of these plugins are not ready for this iteration of the framework, so we will have to make some adjustments to a few of them. Luckily, not all plugins need to be tweaked. Some are ready for Bootstrap 4 out-of-the-box, and due attention has been paid to giving clarifications on the status of each of the plugins used in this chapter regarding the compatibility issues with Bootstrap 4.

Converting checkboxes into Toggles with Bootstrap Toggle plugin

In this recipe, we will use the Bootstrap Toggle plugin, which has not been updated for over a year at the time of writing this book. The plugin is also intended to be used with Bootstrap 3. Luckily, it will not take us a lot of effort to adjust the behavior of this plugin to work with Bootstrap 4.

Getting ready

To begin this recipe, navigate to the Bootstrap Toggle plugin repository, available at https://github.com/minhur/bootstrap-toggle.
Specifically, we need two files from this repository:
  • The plugin's CSS, available at https://github.com/minhur/bootstrap-toggle/blob/master/css/bootstrap-toggle.css
  • The plugin's JS, available at https://github.com/minhur/bootstrap-toggle/blob/master/js/bootstrap-toggle.js
There is also a Bower installation available for this plugin, by running the bower install bootstrap-toggle code (as described in the official plugin website, at http://www.bootstraptoggle.com).

How to do it…

  1. Copy the raw CSS code from the GitHub link at https://raw.githubusercontent.com/minhur/bootstrap-toggle/master/css/bootstrap-toggle.css.
  2. Open the currently blank recipe06-01.scss and paste the code copied from step 1.
  3. Starting on line 58, add the following code to recipe06-01.scss:
 // added
.toggle-handle {
background: #ddd;
}

// added
.btn.active.toggle-off {
box-shadow: inset 0 3px 5px rgba(0,0,0,.125);
color: #333;
background-color: #e6e6e6;
border-color: #adadad;
}
  1. Open the currently empty file titled recipe06-01.ejs, which can be found inside the app folder, and paste the following code:
 <div class="container">

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

</div><!-- /.container -->

<div class="col-12 col-md-5">

<div class="checkbox">
<label>
<input type="checkbox" data-toggle="toggle">
Option one is enabled
</label>
</div>
<div class="checkbox disabled">
<label>
<input type="checkbox" disabled data-toggle="toggle">
Option two is disabled
</label>
</div>

<div class="form-check mb-2 mr-sm-2 mb-sm-0">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"> Remember me
</label>
</div>

</div>
  1. Add the following code to main.scss:
 @import "./bower_components/bootstrap/scss/bootstrap.scss";
@import "./bower_components/bootstrap/scss/_mixins.scss";
@import "./bower_components/font-awesome/scss/font-awesome.scss";
@import "./bower_components/hover/scss/hover.scss";
// @import "./bower_components/bootstrap-toggle/css/bootstrap-toggle.css";

@import "recipe06-01.scss";
  1. In app/partial/_js.ejs, on line 9, insert the following GitHub CDN link:
 <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script> 
  1. Run the grunt and harp server commands in separate Bash windows, and preview the result in the browser at localhost:9000/recipe06-01.

How it works…

We used an outdated plugin that was built for Bootstrap 3. However, many of these plugins require just a few simple tweaks to make them work on frontend projects other than Bootstrap 3. In the case of using the plugin with Bootstrap 4, we achieved the desired effect with a few changes to our CSS and HTML, as can be seen in recipe06-01.scss and recipe06-01.ejs. Finally, we referenced the jQuery plugin via GitHub CDN.

Onboarding users with Shepherd

Onboarding is a way to show first-time visitors to your website how to use your site and to showcase its features. It is a great way to get people introduced to what your site offers in a step-by-step fashion.
In this recipe, we will look at using the Shepherd plugin to onboard users. It is available from http://github.hubspot.com/shepherd/docs/welcome/. The official repository is available at https://github.com/HubSpot/shepherd.

Getting ready

To get ready, simply read through the documentation at GitHub. Also, look at the official website for an example of what is possible with this plugin.

How to do it…

  1. Open app/partial/_js.ejs and add the following code:
 <%- partial("_recipe-06-02-js") %> 
  1. Open app/recipe06-02.ejs and paste this code:
 <div class="container">
<div class="mt-5">
<h1><%- title %>...

Table of contents

  1. Title Page
  2. Copyright
  3. Credits
  4. About the Author
  5. About the Reviewer
  6. www.PacktPub.com
  7. Customer Feedback
  8. Preface
  9. Installing Bootstrap 4 and Comparing Its Versions
  10. Layout Like a Boss with the Grid System
  11. Power Up with the Media Object, Text, Images, and Tables
  12. Diving Deep into Bootstrap 4 Components
  13. Menus and Navigations
  14. Extending Bootstrap 4
  15. Make Your Own jQuery Plugins in Bootstrap 4
  16. Bootstrap 4 Flexbox and Layouts
  17. Workflow Boosters
  18. Creating a Blog with Jekyll and Bootstrap 4
  19. Bootstrap 4 with ASP.NET Core
  20. Integrating Bootstrap 4 with React and Angular