Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Bootstrap 4 Site Blueprints

You're reading from   Bootstrap 4 Site Blueprints Design mobile-first responsive websites with Bootstrap 4

Arrow left icon
Product type Paperback
Published in Oct 2016
Publisher Packt
ISBN-13 9781785889653
Length 404 pages
Edition 2nd Edition
Languages
Arrow right icon
Authors (3):
Arrow left icon
David Cochran David Cochran
Author Profile Icon David Cochran
David Cochran
Ian Whitney Ian Whitney
Author Profile Icon Ian Whitney
Ian Whitney
Bass Jobsen Bass Jobsen
Author Profile Icon Bass Jobsen
Bass Jobsen
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Getting Started with Bootstrap FREE CHAPTER 2. Creating Your Own Build Process with Gulp 3. Customizing Your Blog with Bootstrap and Sass 4. Bootstrappin' a WordPress Theme 5. Bootstrappin' Your Portfolio 6. Bootstrappin' Business 7. Bootstrappin' E-Commerce 8. Bootstrappin' a One-Page Marketing Website 9. Building an Angular 2 App with Bootstrap

Tooling setup

To use the Grunt file and run Bootstrap's documentation locally, you'll need a copy of Bootstrap's source files, Node, and Grunt. Use the following steps to start working with Bootstrap's build process:

  • Install the Grunt command line tools, grunt-cli, with npm install -g grunt-cli
  • Navigate to the root /bootstrap directory and run npm install to install our local dependencies listed in package.json
  • Install Ruby and install Bundler with gem install bundler, and finally run bundle install. This will install all Ruby dependencies, such as Jekyll and plugins

Now you can run the documentation locally by running the following command from the root /bootstrap directory in your console:

bundle exec jekyll serve

After the preceding step, the documentation and examples are available at http://localhost:/9010.

The HTML starter template

After downloading the Bootstrap source files, you can link the compiled CSS and JavaScript files from the dist folder to your HTML. You can do this by creating a new HTML template. Your HTML template should look like the following:

<!DOCTYPE html>
<html lang="en">
  <head>
  <!-- Required meta tags always come first -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css">
  </head>
  <body>
  <h1>Hello, world!</h1>
  <!-- jQuery first, then Bootstrap JS. -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.1.2/js/tether.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
  </body>
</html>

As seen above, your HTML code should start with the HTML5 doctype: <!DOCTYPE html>

Responsive meta tag

Because of the responsive and mobile first nature of Bootstrap, your HTML code should also contain a responsive meta tag in the head section which looks like the following:

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

The mobile first strategy of Bootstrap means that the code is optimized for mobile devices first. CSS media queries are used to add more features for larger screen sizes.

The X-UA-Compatible meta tag

The X-UA-Compatible is another important meta tag which should be added to the head section of your HTML template. It should look like the following:

<meta http-equiv="x-ua-compatible" content="ie=edge">

The preceding meta tag is forcing Internet Explorer to use its latest rendering mode.

Bootstrap's CSS code

Of course you should also link Bootstrap's CSS code to your HTML document, the example template above loads the CSS code from CDN. You can replace the CDN URI with your local copy found in the dist folder as follows:

<link rel="stylesheet" href="dist/css/bootstrap.min.css">

The JavaScript files

And finally, you should link the JavaScript files at the end of your HTML code for faster loading. Bootstrap's JavaScript plugin requires jQuery, so you have to load jQuery before the plugins. The popover and plugins also require the Tether library which requires jQuery too. Link Tether after jQuery and before the plugins. Your HTML should look like the following:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.1.2/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>

Of course you can link local copies of the files instead of the CDN URIs too.

You have been reading a chapter from
Bootstrap 4 Site Blueprints - Second Edition
Published in: Oct 2016
Publisher: Packt
ISBN-13: 9781785889653
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime