Bootstrap Introduction
Goals
Bootstrap is the most popular front-end framework, and its third version (v3.0.0) has now been released. This tutorial will get you started with Bootstrap 3.
You will also see how to use the framework's box features to customize something distinctive, such as using the grid to create layouts, creating navigation with nav, using carousal to create dropdowns, adding social plugins and third-party plugins such as Google Map.

What is Bootstrap
Bootstrap is a front-end framework for rapidly developing web applications and websites.
In modern web development, there are several components needed in almost every web project.
Bootstrap provides you with all these basic modules - Grid, Typography, Tables, Forms, Buttons, and Responsiveness.
In addition, there are many other useful front-end components, such as Dropdowns, Navigation, Modals, Typehead, Pagination, Carousal, Breadcrumb, Tab, Thumbnails, Headers, and more.
With these, you can build a web project and make it run faster and more easily.
Moreover, since the entire framework is modular, you can customize it with bits of your own CSS, or even with a major overhaul after the project has started.
It is based on several best practices, and we think this is a great time to start learning modern web development; once you have mastered the basics of HTML and JavaScript/jQuery, you can apply that knowledge in web development.
Although there is criticism that all projects built with Bootstrap look the same, and that you can build a website without knowing much HTML + CSS, we need to understand that Bootstrap is a general-purpose framework; like any other general-purpose thing, you need to customize it to make it unique. When you want to customize it, you need to dig deeper, which is not feasible without a solid HTML + CSS foundation.
Of course, besides Bootstrap there are many other good front-end frameworks; which framework to use is the developer's choice, but Bootstrap is definitely worth trying.
WhyTouse Bootstrap in your project?
Download and Understand the File Structure
You can download the jQuery EasyUI version you need from https://github.com/twbs/bootstrap/archive/v3.0.0.zip or https://github.com/twbs/bootstrap/releases/download/v3.0.0/bootstrap-3.0.0-dist.zip Download Bootstrap Version 3.0.0 from there. We use the first one; you can also use the second.
In addition, the code we provide for download includes a folder with bootstrap code downloaded via the first link. It also contains custom.css, the original CSS used to customize Bootstrap.
After unzipping, you will find some files and folders inside the root folder bootstrap-3.0.0.
The main CSS file - bootstrap.css and its minified version bootstrap-min.css - are located in the 'css' folder inside the 'dist' folder under the root folder bootstrap-3.0.0.
Inside 'dist', there is a 'js' folder containing the main JavaScript file bootstrap.js and its minified version.
Inside the root folder, there is a separate 'js' folder containing different JavaScript plugins in different files.
Inside 'assets' in the root folder, you will find another 'js' folder. This holds html5shiv.js, the HTML5 shim, for IE8 support. There is also a respond.min.js file for supporting media queries in IE8. This folder also contains jquery.js, which Bootstrap's JS plugins depend on.
In the same folder, there is an 'ico' folder containing the favicon and various mobile device icons.
The 'css' folder in the same path contains the documentation's CSS files.
The '_includes' and '_layouts' folders contain some default layout structure files, which may be useful for rapid prototyping.
The 'less' folder in the root folder contains some .less files. These will be useful if you want to develop based on LESS.
In the root folder, there are some files. Some are HTML files for basic prototyping, and some are bower.json and browserstack.json for Bower-based compilation. Besides these, there are composer.json and a YAML file, _config.yml.
Besides downloading from the given links, you can also use the following command to compile all the CSS and JS files -
$ bower install bootstrap
You can clone Bootstrap's Git repository
git clone git://github.com/twbs/bootstrap.git
In this tutorial, we only downloaded the Zip file and did not actually use it.
Once you have studied this tutorial, we encourage you to install the framework via bower to understand how it works.
NetDNA hosts compiled and minified versions of Bootstrap CSS, JS, and other theme CSS. You can reference them with the following statements
Developing with Bootstrap v3.0.0
Basic HTML
The following is the basic HTML structure that will be used for our project
Bootstrap V3 template
Hello, world!
Note that the *html5shiv.js and respond.min.js added in the template are for IE8 support. These files have been added in Bootstrap version 3. *
We have placed the bootstrap-3.0.0 folder inside the twitter-bootstrap folder in the root folder of the web server. All the HTML files we create will be placed inside twitter-bootstrap. We mention this to simplify our development process.
Customization
We willcustomize distinctive CSS box stylesSo, without breaking the original CSS files (located in the dist folder of bootstrap-3.0.0), in the same folder we will create a separate CSS file named custom.css. Then in the HTML file, right after the original CSS file, we will reference this CSS file. This way, we can override the default styles we want to change, but if Bootstrap is upgraded, the original CSS files will be updated without breaking our customization. We recommend you follow this approach in your development process as well.
Creating Navigation
To create navigation, add the following code in the HTML file, right after the opening tag of the body.
For navigation, Bootstrap uses the 'navbar' class at the container level. So, it is assigned to the nav element that holds the entire navigation.
We have used the 'navbar-inverse' class to change the default color of the navigation bar, using a dark color instead of the previous default light color. The 'navbar-fixed-top' class ensures that the navigation bar stays fixed at the top when we scroll down the HTML page.
In Bootstrap V3.0.0, using role="navigation" when creating navigation is newly addedBootstrap recommends this so that the navigation bar iseasily accessible。
At this point, we added 'padding-top: 80px;' to the body in the custom.css file. The number of pixels you add to the body as top padding may vary, but unless you do this, the top part of the content after the navigation bar will be hidden.
Inside the container nav, we have an unordered list with classes 'nav' and 'navbar-nav'. Within this unordered list, each list item contains a link in the navigation.
The 'navbar-brand' class is used to present the brand name. We have used an image. Since the image's height is greater than the navigation bar's baseline height, we do some customization here. We increase the 'line-height' property of '.navbar-nav>li>a' from the original default of 20px to 50px, and change the font size to 16px.
For the rightmost link, we have added a dropdown. For the 'dropdown' class added to the relevant li, immediately after it, add an anchor with the two classes 'dropdown-toggle' and 'caret'. This anchor actually contains the anchor text social in our project. This li then contains an unordered list, and each list item nested in the list contains a link displayed in the dropdown.
In the dropdown we have added social plugins. The first li contains the Google Plus markup, the second li contains the Facebook markup, and the third li contains the markup to display the Twitter button and some JS scripts.
In addition, you must add the following markup and scripts after the opening tag of the body to make the Facebook button work
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
To make the Twitter button work, we add the following script before the closing tag of the body
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
We use the following styles to add some extra styling to the social buttons of the 'socials' class.
.socials {
padding: 10px;
}
This completes our navigation.
Creating a Carousel with carousal
To create a carousel under the navigation bar on the project's home page, we will use the following markup
There are four parts in a Carousal. The main container is defined using a div tag with the 'carousel slide' class.
Then there is an ordered list with the 'carousel-indicators' class. Each list item in the ol represents a slide. When the page loads, the slide loaded by default has the 'active' class. When rendered, you will see them as small circles below the title.
Then, each slide (image) is placed in a div tag with the 'item' class. Each item is nested in a div with the 'carousel-caption' class. carousel-caption contains some markup displayed as a caption along with the image. The paragraph contains an h1 and a button; you can also include other markup of your own.
The last part is for controlling the next/previous slide. The previous is defined using the 'left' and 'carousel-control' classes, and the next using the 'right' and 'carousel-control' classes.
The 'icon-prev' and 'icon-next' classes are used for the next and previous icons.
We havemade some customizations to the default carousalWe want the captions, indicators, and next/previous icons to be rendered a few pixels above their default positions.
To do this, we add the following styles in the custom.css file
.carousel-inner .item .carousel-caption {
position:absolute;
top: 200px
}
.carousel-indicators {
position: absolute;
top: 400px;
}
.navbar {
margin-bottom:0;
}
.navbar-nav>li>a {
line-height: 50px;
font-size: 16px
}
We also customized the h1, adding a 30-pixel bottom margin to it.
h1 {
margin-bottom: 30px
}
Responsive Images
You may have noticed that for each image in the carousel, we have used the 'img-responsive' class. This is a new feature in Bootstrap v3.0.0.By using the 'img-responsive' class in the img tag, Bootstrap makes images responsive。
Creating the Grid
Below the carousel, we use the grid to place content. A grid starts with a div with the 'container' class. Note that we are going to develop a responsive website, and unlike previous versions of Bootstrap, here the container has a single class, which is responsive by default.
The container div nests several divs with the 'row' class (three in the first row and six in the second row), used to create the rows of the Bootstrap grid.
Each row has a div with the 'col-x-y' class to create columns. The value of x can be: xs for mobile devices, sm for tablets, md for laptops and smaller desktop screens, and lg for large desktop screens. This is the first method. The value of y can be any positive integer, but the total number of columns in the grid must not exceed 12. In our project, we have used lg for simplicity, but now that we have done so, you may want to view the project site on a phone or tablet for comparison.
In a later tutorial, we will have a complete tutorial on the Bootstrap grid system to explore its fascinating responsive features.
In this example, we want the three columns in the first row to have equal width, so we use 'col-lg-4' for all of them. In the second row, we want the six columns to have equal width, so we use 'col-lg-2' for all of them.
The following is the markup for the grid containing two rows, with three columns in the first row and six columns in the second row.
We end the grid with an hr and a footer with the following markup
Copyright@2013-14 by ToDo App.
Using Tables
In our project's price.html page, we used a table to present a price list, with the markup as follows
Features
Individual
Small Team
Medium Team
Enterprise
No. Of users
One
Five
Fifteen
Unlimited
Pro training
No
Yes
Yes
Yes
Forum Support
Yes
Yes
Yes
Yes
In person support
No
No
Yes
Yes
Weekly webinars
No
No
Yes
Yes
Price
We use the 'table' and 'table-bordered' classes from Bootstrap's original CSS file. But we have added the following CSS in the customize.css file to make some customizations so the table looks different
th {
background-color: #428bca;
color: #ec8007;
z-index: 10;
text-shadow: 1px 1px 1px #fff;
font-size: 24px;
}
Using Badges
We use the 'badge' class to display some text in the table. We have a custom badge class with the following CSS
.badge {
background-color: #428bca;
color: #fff;
font-size: 22px;
}
For this page and the contact.html page, we added another CSS rule in customize.css
.container > h1 {
text-align: center;
}
This centers the h1.
Using Forms
In the contact.html file, we created three columns, and in the first column we embedded a form. The form uses the default styles.
The 'form-horizontal' class keeps the form horizontally aligned.Note that role="form" is added for accessibility. This is a new feature in version 3.0.0.
To position each form control, Bootstrap 3.0.0 uses a new 'form-group' class.
On this page, in the second column of the grid, we simply placed some text.
Adding a Google Map
In the contact.html page, in the third column of the grid, we added a Google Map. To do this, we used the following markup
The following JS is added to the header at the top of the HTML file
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(23.244066, 87.861276),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
Before the JS mentioned above, you must add the following script tag
To render the map correctly, you must add the following styles in custom.css
#map_canvas {
width: 400px;
height: 400px;
}
This is how to create a simple project based on Bootstrap V3.0.0. But we have only scratched the surface; later chapters will explain things in more detail.




