Bootstrap 3 3 A Guide Book For Beginners To Learn Web Framew PDF
Bootstrap 3 3 A Guide Book For Beginners To Learn Web Framew PDF
3.3
A Guide Book for Beginners to Learn Web
Framework Fast!
Kevin Lyn.
Copyright © 2015 by Kevin Lyn.
Disclaimer
While all attempts have been made to verify the information provided in this book, the
author doesn’t assume any responsibility for errors, omissions, or contrary interpretations
of the subject matter contained within. The information provided in this book is for
educational and entertainment purposes only. The reader is responsible for his or her
own actions and the author does not accept any responsibilities for any liabilities or
damages, real or perceived, resulting from the use of this information.
www,engbookspdf.com
Table of Contents
Book Description
Introduction
Chapter 1: Definition
Chapter 2: Getting started with Bootstrap
Chapter 3: Grid System in Bootstrap
Chapter 4: Fixed Layout with Bootstrap
Chapter 5: Tables in Bootstrap
Chapter 6: Lists in Bootstrap
Chapter 7: Creating Forms with Bootstrap
Chapter 8: Styling Images with Bootstrap
Chapter 9: Buttons in Bootstrap
Chapter 10: Modals in Bootstrap
Chapter 11: Accordion in Bootstrap
Chapter 12: Bootstrap Carousel
Conclusion
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Book Description
This book is all about bootstrap. After reading it, you will know how to use bootstrap for
development. You will also know the constituent components of bootstrap. The two types
of bootstrap, that is, the compiled and the source code files are explored in detail with
emphasis on the difference between the two types.
Here you will learn how to predict the appearance of a web page on different devices and
screens depending on the kind of layout you have used. Tables, which are a common
feature in web development have been discussed. Adding hover, borders, adding
background features and as well as differentiating the rows of a table have been discussed.
The files which are usually found in the bootstrap folder are also explained in terms of
what they do. You will also be guided on how to include these bootstrap files in your
project and even in the header of your code. The different types of layouts which are
available in bootstrap are explored in detail and their effect on devices with different
screen sizes.
You will also know how to make responsive tables with bootstrap so that they can appear
well on different devices regardless of the screen size. Lists are also explored in this book.
The different types of buttons are also explored, and as well as images and forms in
bootstrap.
www,engbookspdf.com
Modals, accordions and carousel, which are advanced features in bootstrap have also been
discussed in this book. There are code examples as well as pictures in this book for ease of
understanding. The following topics have been discussed:
Definition
Getting started
Grid system in Bootstrap
Fixed Layout
Tables
Lists
Forms
Styling Images
Buttons
Modals
Accordion
Carousel
www,engbookspdf.com
www,engbookspdf.com
Introduction
With bootstrap, you can create web pages that will scroll well on any device. Something
like a table, which might seem difficult to fit on a cell phone can be made to do this using
bootstrap. This explains how powerful bootstrap is. This can also be done without too
much coding and in a short period of time.
You might have heard of responsive web design. If not, don’t worry for you’ll understand
what it is after reading this book. You might have realized that some websites are not
accessible via cell phones and tablets, but one can only access them via computers. Web
pages also do not appear the same on devices with different sizes in terms of the layout
and how they scroll.
You know about validation. Instead of using Jquery, with which much coding will be
needed, bootstrap can be used for this purpose using less than 5 words. It has numerous
controls which are available in HTML such as buttons and text fields. With bootstrap,
these can be made beautiful. Image and text sliders can also be made using bootstrap with
much less effort in terms of coding.
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 1:
Definition
Ever heard of responsive web design? Bootstrap is a collection of tools which helps
developers in creating responsive websites. Most of today’s websites are not responsive,
meaning that you can only access them via computers. Devices with small screen such as
mobile phones and tablets cannot access these websites.
This is why Jacob Thornton and Mark Otto developed bootstrap. With this tool,
developers create websites with amazing features and these can be accessed via devices of
any screen size. Responsiveness is one of the emerging issues in web development, and
this is the reason why you should consider learning bootstrap.
It is compatible with nearly all the browsers currently in use. If you have never used this
tool, you will be amazed how it senses the size of the screen of the device and then it
adjusts the pages of the web page dynamically. Its documentation has been translated into
other languages such as Russian, Spanish and Chinese.
If you have not downloaded it, it is available for free download on Github, so you can get
it from there. The process of creating a responsive layout with bootstrap is much easy such
that even beginners will find it easy. The tool is based on HTML and CSS.
www,engbookspdf.com
Some of the interface components that can be created with bootstrap include carousel,
buttons, modals, accordion, forms, tables, dropdowns, alerts, navigation and tabs. It also
offers Javascript extensions which are optional.
1. Responsive design- with bootstrap, web pages appear well on devices with
different screen sizes and resolution. You will not observe any change in markup.
2. Easy to learn and use- provided you know the basics of HTML and CSS, you
don’t need to learn bootstrap. You only need to get started.
3. Saves time- instead of defining your own classes, you just use the predefined
bootstrap classes and templates and then use that doing in doing other development work.
browsers such as Google Chrome, Mozilla Firefox, Safari, Opera and Internet Explorer.
5. Consistency in Design- through a central library, all of the components of this tool
share the same design styles and templates which have led to consistency.
www,engbookspdf.com
It is worth to note that some properties such as shadows, rounded corners and gradients
which are supported by CSS3 are also supported in Bootstrap. However, when you use
older versions of browsers such as the Internet explorer and you have developed these
features with bootstrap, they will not be supported.
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 2:
Before you can begin to use bootstrap, it is good to make sure that you understand the
basics of both HTML and CSS as these are the building blocks of bootstrap. Also, ensure
that your computer has an editor of choice. I don’t prefer the basic ones such as notepad.
You can download and install Dreamweaver or Notepad++.
When downloading bootstrap files, you will be availed with two versions, the Bootstrap
source files and the Compiled Bootstrap files. The source version always contains
original source files for all Javascript and CSS and a local copy of the documents.
The compiled version contains the minified and compiled versions of Javascript and CSS
files. For easy and faster web development, it has icons in font format. In this book, we are
going to use the compiled version of bootstrap. It is easy for understanding and saving of
time since as the programmer, you will not be needed to include separate files for each
functionality.
It also has less HTTP request, hence you will save on bandwidth when moving the site to a
www,engbookspdf.com
production environment. After download the bootstrap file, it will come a zipped format.
Unzip it and you will find the following files:
Css:
bootstrap.css
bootstrap.min.css
bootstrap-theme.css
bootstrap-theme.min.css
js:
bootstrap.js
bootstrap.min.js
fonts:
glyphicons-halflings-regular.eot
glyphicons-halflings-regular.svg
glyphicons-halflings-regular.ttf
glyphicons-halflings-regular.woff
The above are the components of the compiled version of bootstrap. It has the compiles
Javascript and CSS files and a fonts file. The four files contain 200 icons.
www,engbookspdf.com
Now that you have known the structure of the bootstrap, let us create our first template
using it. Consider the following basic HTML code:
<html>
<head>
<meta charset=“utf-8”>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset=“utf-8”>
www,engbookspdf.com
<title>A Bootstrap Template</title>
</head>
<body>
<h1>Hello world</h1>
<script src=“http://code.jquery.com/jquery.min.js”></script>
<script src=“js/bootstrap.min.js”></script>
</body>
</html>
Be keen when specifying the path where the bootstrap files are located. Note that we have
added three files to develop the template. You can now save the template and give it a
name of choice.
Ensure that the name has a .html extension. You can then navigate to the location where
you have saved the file and double click on it or right click on it and choosing “Open”. It
will open with the default browser of your computer. Text written “Hello world” will be
printed on the browser. In case the file doesn’t open after using the above two methods,
just open a browser and drag it there. It will open.
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 3:
This makes it possible for web developers to create different layouts for their web pages.
In Bootstrap 3, this grid system can span up to 12 columns depending on the screen size of
the device. This type of grid system is called mobile first fluid grid system.
Developers have used this to create websites which can be accessed using any device
regardless of the screen size. This version of bootstrap also has different classes for
making layouts of different devices such as tablets, desktops and cell phones.
With bootstrap, one can determine and control how the pages of the website will look on
different devices with different screen sizes. Consider the following devices:
www,engbookspdf.com
We have presented the four screens each with 12 content boxes. However, the arrangement
is not the same on all screens. The first screen illustrates the screen of a cell phone. The
content boxes have been arranged vertically and each occupies a row.
The second screen illustrates a device such as a desktop with a large display. The content
boxes have been arranged in a 4 *3 grid layout. The third screen illustrates what we have
in a device such as a tablet. The content boxes have been arranged in a 2 * 6 grid layout.
The last screen illustrates what we have in a laptop with a medium sized screen. The
content boxes have been represented in a 3 * 4 grid layout.
Now that we have the four screens, how can you create a layout to fit in any of the above
screens? That’s what we going to tackle. Let us start with the device having a medium
sized screen such as a laptop. Type the following code and run it on such a device:
< html>
<html lang=“en”>
<head>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
www,engbookspdf.com
p{
background: #f2f2f2;
padding: 52px;
font-size: 30px;
text-align: center;
font-weight: bold;
</style>
</head>
<body>
<div class=“container”>
<div class=“row”>
<div class=“col-md-4”><p>1</p></div>
<div class=“col-md-4”><p>2</p></div>
<div class=“col-md-4”><p>3</p></div>
<div class=“col-md-4”><p>4</p></div>
www,engbookspdf.com
<div class=“col-md-4”><p> 10</p></div>
</div>
</div>
</body>
</html>
Follow the steps we did in our first example to run the file after saving it. If you use a
medium sized device such a laptop, the output will be boxes arranged in a 3 * 4 grid
layout, that is, 4 rows and 3 columns. However, you notice that if any of the columns is
taller than the others, it will not clear properly. Fix this by adding .clearfix and the classes
<!DOCTYPE html>
<html lang=“en”>
<head>
<link rel=“stylesheet”
href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css”>
<link rel=“stylesheet”
href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css”>
www,engbookspdf.com
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script src=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js”>
</script>
<style type=“text/css”>
p{
font-size: 32px;
font-weight: bold;
padding: 50px;
background: #f2f2f2;
text-align: center;
</style>
</head>
<body>
<div class=“container”>
<div class=“row”>
www,engbookspdf.com
<div class=“col-md-4”><p> 5</p></div>
</div>
</div>
</body>
</html>
That’s for a laptop. Let us to the same for a tablet which has 2 * 6 grid layout. The code
should be as follows:
<!DOCTYPE html>
<html lang=“en”>
<head>
www,engbookspdf.com
<link rel=“stylesheet” href=” css/bootstrap-theme.min.css”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script src=“js/bootstrap.min.js”></script>
<style type=“text/css”>
p{
background: #f2f2f2;
padding: 50px;
font-size: 32px;
text-align: center;
font-weight: bold;
</style>
</head>
<body>
<div class=“container”>
<div class=“row”>
www,engbookspdf.com
<div class=“col-sm-6 col-md-4”><p> 5</p></div>
</div>
</div>
</body>
</html>
For small devices such as the mobile phones, the clearing will look as follows:
<div class=“container”>
<div class=“row”>
www,engbookspdf.com
<div class=“col-sm-6 col-md-4”><p> 2</p></div>
</div>
</div>
www,engbookspdf.com
Lastly, for large screens such as desktops, the clearing would be as follows:
<div class=“container”>
<div class=“row”>
www,engbookspdf.com
<div class=“clearfix visible-md-block”></div>
</div>
</div>
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 4:
You can use bootstrap to create pages for a web with a fixed number of pixels. The good
thing with this is that it will remain responsive on all devices even though you are not
required to include the responsive style sheet. In this case, we start with the class
.container.
For us to wrap the horizontal groups of columns, we use the .row class. For you to ensure
that there is a proper padding and alignment, all rows must be placed in the .container
class. Creation of columns can then be done within the rows using classes such as .col-sm-
*, .col-xs-*,.col-lg-* and .col-md-* .
Note that * stands for the number of grids which can take values from 1 to 12. Let us
illustrate this with a code which will create a fixed width page with 750px and it is
responsive. This web page should be 750px wide on a device such as a tablet which has a
small screen size, 970px wide on a device with a medium sized display such a laptop and
1170px wide on devices with large display size such as large desktops.
On devices such as cell phones whose display is small (<768px), the layout width will be
calculated automatically.
www,engbookspdf.com
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“utf-8”>
</head>
<body>
<div class=“container”>
<div class=“navbar-header”>
<span class=“icon-bar”></span>
<span class=“icon-bar”></span>
www,engbookspdf.com
<span class=“icon-bar”></span>
</button>
</div>
<!—Collect content for forms, nav links, and others for toggling purpose —>
</ul>
</div>
</div>
</nav>
<div class=“container”>
<div class=“jumbotron”>
<p>With Bootsrap, one can create a fixed and responsive web </p>
started</a></p>
</div>
www,engbookspdf.com
<div class=“row”>
<div class=“col-xs-4”>
<h2>HTML</h2>
<p>HTML is also good for creating web pages. It is one of the constituent components
of bootstrap.</p>
</div>
<div class=“col-xs-4”>
<h2>CSS</h2>
<p>CSS is a good when it comes to presentation of a web page. On can also add many
styles to the web page with this. Colors, padding and indentation can be achieved with
CSS, thus, it is a very powerful tool. It is a constituent component of Bootstrap along with
HTML</p>
</div>
<div class=“col-xs-4”>
<h2>Bootstrap</h2>
<p>Bootstrap is a tool for responsive web design, with which a developer can achieve
amazing functionalities, and with less effort and within a short period of time. </p>
</div>
www,engbookspdf.com
</div>
<hr>
<div class=“row”>
<div class=“col-xs-12”>
<footer>
<p>Bootstrap book</p>
</footer>
</div>
</div>
</div>
</body>
</html>
Once you have saved the file with a .html extension, just run it. The first part of the output
will be a navigation bar containing menus. The first menu will be written “Bootstrap
book”. The other menus will appear as follows:
At the center of the web page should be a description of the title “Learn to use Bootstrap”.
The description for HTML, CSS and Bootstrap will also be shown. Notice the color of the
buttons used in this example. They are all green. This is because we have used the button
www,engbookspdf.com
success. There are many other types of buttons and you will learn these as we progress.
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 5:
Tables in Bootstrap
Bootstrap can be used to enhance how your table looks like. This means that one can
improve tables from what they can create using pure HTML. Let us begin y creating a
simple table using the .table class in bootstrap:
<table class=“table”>
<thead>
<tr>
<th>Row Number</th>
<th>FName</th>
<th>LName</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
www,engbookspdf.com
<td>Michael</td>
<td>Joseph</td>
<td>[email protected]</td>
</tr>
<tr>
<td>2</td>
<td>john</td>
<td>Parker</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>peter</td>
<td>mary</td>
<td>[email protected]</td>
</tr
</tbody>
</table>
On running the code above, the following output will be displayed on your browser:
www,engbookspdf.com
You can add additional features to your table such as stripes resembling the ones of a
zebra. Run the following code and observe the output:
<thead>
<tr>
<th>Row Number</th>
<th>FName</th>
<th>LName</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
www,engbookspdf.com
<td>Peter</td>
<td>mary</td>
<td>[email protected]</td>
</tr>
<tr>
<td>2</td>
<td>john</td>
<td>Parker</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>emmanuel</td>
<td>ken</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
After running the above code, the following output will be observed:
www,engbookspdf.com
To add borders to each cell of the table, use the class .table-bordered. Add it to the .table
base class. Run the following code and observe the output:
<thead>
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
www,engbookspdf.com
<td>Peter</td>
<td>mary</td>
<td>[email protected]</td>
</tr>
<tr>
<td>2</td>
<td>john</td>
<td>Parker</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>emmanuel</td>
<td>ken</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
After running the code, the following table will be displayed on the browser:
www,engbookspdf.com
www,engbookspdf.com
Hover state on Table Rows
This can be enabled on the rows of the table by simply using the .table-hover bootstrap
class. This can be added to the .table class and within the <tbody> element. Write the
<thead>
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Peter</td>
<td>mary</td>
<td>[email protected]</td>
www,engbookspdf.com
</tr>
<tr>
<td>2</td>
<td>john</td>
<td>Parker</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>emmanuel</td>
<td>ken</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
On running the code above, you will notice that the movement of the cursor on the table is
being tracked. This is what we call hover:
www,engbookspdf.com
Note that in our example, the cursor is on the second row of the table and that’s why it is
highlighted.
www,engbookspdf.com
Condensed Tables
You can choose to save on save by making your table more compact. This can be achieved
by using the .table-condensed class which should added to the .table class. Write and run
<thead>
<tr>
<th>Row Number</th>
<th>FName</th>
<th>LName</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Peter</td>
<td>mary</td>
<td>[email protected]</td>
www,engbookspdf.com
</tr>
<tr>
<td>2</td>
<td>john</td>
<td>Parker</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>emmanuel</td>
<td>ken</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
You will notice that the output table will be much condensed compared to what we had in
our previous examples. You will have saved on space.
www,engbookspdf.com
Differentiating Table Rows
You can put emphasis on a particular table row to ensure that it looks unique from the rest
of the rows. This will enable you to uniquely identify this row. Consider the example
below:
<table class=“table”>
<thead>
<tr>
<th>Row Number</th>
<th>Your Bill</th>
<th>Payment Status</th>
</tr>
</thead>
<tbody>
<tr class=“active”>
<td>1</td>
<td>Bank</td>
<td>08/09/2013</td>
www,engbookspdf.com
</tr>
<tr class=“success”>
<td>2</td>
<td>Water</td>
<td>02/08/2013</td>
<td>Cleared</td>
</tr>
<tr class=“info”>
<td>3</td>
<td>Internet</td>
<td>07/08/2013</td>
<td>Plan to be changed</td>
</tr>
<tr class=“warning”>
<td>4</td>
<td>Electricity</td>
<td>08/07/2013</td>
<td>Awaiting</td>
</tr>
<tr class=“danger”>
<td>5</td>
www,engbookspdf.com
<td>Telephone</td>
<td>08/09/2013</td>
<td>Overpay</td>
</tr>
</tbody>
</table>
Now try to run the code above. The output table will be very amazing as shown below:
In most devices and especially the ones with a small display size, tables do not scroll well.
With bootstrap, this problem can be solved such that your tables can scroll well even on
cell phones. On devices with large displays, you will not notice any display. Write the
following code on your editor:
www,engbookspdf.com
<div class=“table-responsive”>
<thead>
<tr>
<th>Row Number</th>
<th>FName</th>
<th>LName</th>
<th>Email</th>
<th>History</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Peter</td>
<td>Mark</td>
<td>[email protected]</td>
</tr>
<tr>
<td>2</td>
www,engbookspdf.com
<td>Victor</td>
<td>Benjamin</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>Alphonse</td>
<td>David</td>
<td>[email protected]</td>
<td>A mathematician…</td>
</tr>
</tbody>
</table>
</div>
Once you have written the code above, run it on a device having a large display such as a
desktop. Observe how the table is aligned or how it scrolls. Run it on a device with a
medium sized display such as a laptop and again, observe how the table behaves.
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 6:
Lists in Bootstrap
Lists are common elements in web design. You might need to use them in the course of
programming. With bootstrap, you can create the following types of lists:
1. Ordered Lists- a kind of list where order is really important. The elements in an
2. Unordered List- order in this kind of list does not matter. The elements in this
list are marked by use of bullets.
List items usually come with a default styling. However, you might need to do away with
this style for some reasons. This can be achieved by using the class .list-unstyled. Write
www,engbookspdf.com
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script src=“bootstrap/js/bootstrap.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
</style>
</head>
<body>
<div class=“ls-example”>
<ul class=“list-unstyled”>
<li>Home</li>
www,engbookspdf.com
<li>About
<ul>
<li>Services</li>
<li>Accessories</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
<hr>
<ol class=“list-unstyled”>
<li>Home</li>
<li>About
<ol>
<li>Services</li>
<li>Accessories</li>
</ol>
</li>
<li>Location</li>
<li>Contact</li>
www,engbookspdf.com
</ol>
</div>
</body>
</html>
After running the code above, the following will be the output:
As you can see, there is no the default styling in both unordered and the ordered list since
this is what we have specified.
www,engbookspdf.com
How to place the items of Unordered and ordered List inline
You visit websites regularly. What you see is a list of menus running horizontally across
the screen. These can be created using either ordered or unordered lists. The trick behind
this is that all the items of the list should be placed in a single line. The bootstrap class
.list-inline is used in this case. It is applied to the elements of either the ordered or
unordered list. Once you do this, your menu will be amazing. Write the code below and
run it:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
www,engbookspdf.com
}
</style>
</head>
<body>
<div class=“ls-example”>
<ul class=“list-inline”>
<li>Home</li>
<li>About Us</li>
<li>Services</li>
<li>Location</li>
<li>Contact Us</li>
</ul>
</div>
</body>
</html>
The following should form the output of the code after running it:
It is an amazing menu. If you have never created one, I know you feel after getting the
www,engbookspdf.com
above. Just modify it in case you want to use for your site, but the most important this is to
understand how to create it.
You might need to create a list of terms accompanied by their description. This is much
easy with bootstrap. The bootstrap’s class .dl-horizontal is used for this purpose and it
does automatic adjustment if the content doesn’t fit well. Write the following code and run
it:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
www,engbookspdf.com
}
</style>
</head>
<body>
<div class=“ls-example”>
<dl class=“dl-horizontal”>
<dt>Bootstrap</dt>
<dd>A combination of both HTML and CSS to create responsive web pages</dd>
<dt>CSS</dt>
<dd>CSS is a language used to define how web pages will appear. It is a very powerful
tool with which can add colors and other styles to the web page.</dd>
<dt>PHP</dt>
<dd>A powerful language that can be used to add functionality to an HTML layout.
</dd>
</dl>
</div>
</body>
</html>
Once you run the code, the output will just be the lit of terms we have specified
accompanied by the description on what they are:
www,engbookspdf.com
It is a very amazing feature and you might require to use it somewhere in the course of
programming.
You can use bootstrap’s list groups if you want to group your list items and make them
beautiful by adding some extra features to them. Write the code below and run it:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
www,engbookspdf.com
<script src=” bootstrap/js/bootstrap.min.js”></script>
<style type=“text/css”>
.list-group{
width: 200px;
.ls-example{
margin: 19px;
</style>
</head>
<body>
<div class=“ls-example”>
<ul class=“list-group”>
<li class=“list-group-item”>Home</li>
<li class=“list-group-item”>Services</li>
</ul>
</div>
</body>
</html>
www,engbookspdf.com
It is so amazing compared to what we had in our previous examples. If you such features
on your website, it will be amazing to the people who visit it. The list items have been put
in cells. Hyperlinks can also be added to the above list items if you need to do so. This is
as shown below:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
www,engbookspdf.com
<script src=” bootstrap/js/bootstrap.min.js”></script>
<style type=“text/css”>
.list-group{
width: 200px;
.ls-example{
margin: 20px;
</style>
</head>
<body>
<div class=“ls-example”>
<div class=“list-group”>
</a>
</a>
www,engbookspdf.com
<a href=”#” class=“list-group-item”>
</a>
</a>
</div>
</div>
</body>
</html>
Once you run the code above, you will observe the following output:
The above list items have hyperlinks with them. Icons have also been added to them. If
you a regular computer user, the icons used above exactly match what we have on real
www,engbookspdf.com
computers and this shows how powerful bootstrap is. You should take advantage of these
functionalities to create amazing web pages.
Paragraphs and headings can also be added to a list to enhance the look how of your web
page as shown below:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
</style>
</head>
<body>
www,engbookspdf.com
<div class=“ls-example”>
<div class=“list-group”>
<p class=“list-group-item-text”> CSS is a language used to define how web pages will
appear. It is a very powerful tool with which can add colors and other styles to the web
page.</p>
</a>
</a>
</a>
</div>
</div>
</body>
www,engbookspdf.com
</html>
Once you run the code above, you will observe the following output:
We advanced what we had in our previous example to this. The way the above example
This can be done so as to add extra features and emphasis on a list group just like it is
done on other elements. The result is always a good looking list with features that can be
liked by most people. These range from coloring to other complex features. Write the code
below and run it:
<!DOCTYPE html>
<html lang=“en”>
<head>
www,engbookspdf.com
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
</style>
</head>
<body>
<div class=“ls-example”>
<ul class=“list-group”>
www,engbookspdf.com
while making requests. The server will not provide any service then.</li>
</ul>
</div>
</body>
</html>
Once you run the above code, the following will be the observed output:
As you can see, the output looks beautiful. The background text, text color look very
beautiful and attractive. This is the work of bootstrap. If you want to use this feature on
the linked list group, use the .active class as shown below:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
www,engbookspdf.com
<title> List Group Contextual Classes with Bootstrap</title>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
</style>
</head>
<body>
<div class=“ls-example”>
<ul class=“list-group”>
www,engbookspdf.com
</ul>
</div>
</body>
</html>
After running the above code, you will realize that the only difference with the previous
example is that the latter has some links unlike what we have in the previous example.
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 7:
Forms are regularly used on web pages. They usually prompt users to provide some
information or they might be outputting data to the users. Styling forms using CSS alone
is very tedious and this is why bootstrap came in. You can create amazing form controls
using bootstrap. Bootstrap offers three kinds of layout for your forms which include the
following:
1. Vertical form.
2. Horizontal form.
3. Inline form.
This is the form which is created by default in bootstrap if you don’t specify the kind of
form that you want. The styles are also added by default in case no styles are added to the
www,engbookspdf.com
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
</style>
</head>
<body>
<div class=“ls-example”>
<form>
<div class=“form-group”>
<label for=“userName”>UserName</label>
www,engbookspdf.com
</div>
<div class=“form-group”>
<label for=“password”>Password</label>
</div>
<div class=“checkbox”>
</div>
</form>
</div>
</body>
</html>
Once you run the above code, the following will be the output:
www,engbookspdf.com
The fields for entering text are rounded at the corners, which is a default style in bootstrap.
They look amazing. The purpose of the placeholder is to guide the user, and especially the
novice ones while entering the text. Once you start typing inside the text field, the
placeholder text will disappear. The width of all form controls like text area and text fields
are usually set at 100% wide in bootstrap. If you don’t need them to be like this, you need
to change to your favorite size.
In these kinds of forms, labels are right-aligned. For the sake of making them appear in the
same line as other form controls, they are floated to the left. However, with this form, you
will need to make a lot of changes to it so that it can appear different from what we have
in the default form. The following steps are necessary for you to create an horizontal form:
2. Wrap the form controls including labels in a <div> element. Add the .form-
group to this.
www,engbookspdf.com
3. Align form controls and labels using the bootstrap grid classes.
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
/* use bootstrap to solve the problem of aligning labels on devices with small display
size such as cell phones */
.form-horizontal .control-label{
www,engbookspdf.com
padding-top: 8px;
</style>
</head>
<body>
<div class=“ls-example”>
<form class=“form-horizontal”>
<div class=“form-group”>
<div class=“col-xs-10”>
</div>
</div>
<div class=“form-group”>
<div class=“col-xs-10”>
</div>
</div>
<div class=“form-group”>
www,engbookspdf.com
<div class=“col-xs-offset-2 col-xs-10”>
<div class=“checkbox”>
</div>
</div>
</div>
<div class=“form-group”>
</div>
</div>
</form>
</div>
</body>
</html>
Once you run the code above, the following output will be observed:
www,engbookspdf.com
www,engbookspdf.com
Inline Forms with Bootstrap
This is used when one needs to place the form controls side-by-side. The resulting layout
will be compacted and hence much space will be saved. We use .form-inline which is a
bootstrap class inside the <form> element. Write the code below and run it:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
</style>
</head>
www,engbookspdf.com
<body>
<div class=“ls-example”>
<div class=“form-group”>
</div>
<div class=“form-group”>
</div>
<div class=“checkbox”>
</div>
</form>
<br>
</div>
</body>
</html>
www,engbookspdf.com
The following code should form the output after running it:
As you can see, the controls of the form have been placed side-by-side. Much space has
been saved with this layout. Note that if the device you use to run the above code has a
display with less than 768px, the form will be displayed in the default vertical style. To
see the power of bootstrap in terms of responsiveness, just minimize the size of the
browser and observe what will happen. It will display it vertically. This is exactly what
will happen if the device has a small display such as a cell phone.
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 8:
In web design, it is a common practice to use images. They need to be displayed using the
necessary styles and even at the right location. This can be achieved with bootstrap.
Consider the code below:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
imag{
margin: 10px;
www,engbookspdf.com
}
.ls-example{
margin: 20px;
</style>
</head>
<body>
<div class=“ls-example”>
</div>
</body>
</html>
Specifying correctly the path of the images to be used. Now run the code. The output will
be your images being modified. The first one will be made round, the second one will be
made circular while the last image will be made a thumbnail. It will remain square. This
shows how bootstrap can be used to modify the style of an image.
Thumbnails in Bootstrap
www,engbookspdf.com
Sometimes, you might need to create grids of videos, pictures or even portfolios.
Thumbnails are a good application for this. Consider the following example on how to
create thumbnails:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
</style>
</head>
<body>
<div class=“ls-example”>
<div class=“container”>
www,engbookspdf.com
<div class=“row”>
<div class=“col-xs-3”>
</a>
</div>
<div class=“col-xs-3”>
</a>
</div>
<div class=“col-xs-3”>
</a>
</div>
<div class=“col-xs-3”>
</a>
</div>
www,engbookspdf.com
</div>
</div>
</div>
</body>
</html>
Again, make sure that you specify the correct location of your images, otherwise you will
get an undesired output. Run the code:
He output will be images displayed horizontally. Each of the images will have a text
Written 125 * 125. Each image will be placed on a square with slightly-rounded corners.
www,engbookspdf.com
Media Objects in Bootstrap
You might need to display an image to the right or left of a text such as a comment. This
image might represent the owner of the text or comment. Consider the code below:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
</style>
</head>
www,engbookspdf.com
<body>
<div class=“ls-example”>
<div class=“media”>
</a>
<div class=“media-body”>
</small></h4>
<p>It is true that with bootstrap one can achieve so much. An amazing web page can be
created. This chapter deals with media objects</p>
</div>
</div>
<hr />
<div class=“media”>
</a>
<div class=“media-body”>
<p> It is true that with bootstrap one can achieve so much. An amazing web page can
www,engbookspdf.com
be created. This chapter deals with media objects.</p>
</div>
</div>
</div>
</body>
</html>
What we have done is that we have demonstrated by using a single image. In the first
case, the image has been placed at the beginning of the text and in the second case, it
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 9:
Buttons in Bootstrap
Buttons are highly used when it comes to web design, especially in creating
forms. In bootstrap, there exist many types of buttons, so you use the right button to
indicate the intended status. The following are the available buttons in bootstrap:
1. Default- represented by use of a gray color. Belongs to the class btn btn-
default.
2. Success- represented by use of a green color. Belongs to the class btn btn-
3. Primary- use this button to put emphasis on a primary button if you have used
many buttons. Belongs to the class btn btn-primary.
4. Danger- uses red color to indicate the danger associated with an action. Belongs
to the class btn btn-danger.
www,engbookspdf.com
5. Warning- cautions the user before carrying out a certain action. Has a yellow
color and it belongs to the class btn btn-warning.
btn btn-info.
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
www,engbookspdf.com
.ls-example{
margin: 20px;
</style>
</head>
<body>
<div class=“ls-example”>
<hr>
www,engbookspdf.com
<input type=“button” class=“btn btn-danger” value=“Danger”>
<hr>
</div>
</body>
</html>
After running the above code, the following will form the output:
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 10:
Modals in Bootstrap
Modals are kind of windows which pop up on the screen and provide information to the
user before moving on. They are kind of a dialog box, and with bootstrap, one can easily
create them. They contain header, body and a footer. Write the code below and run it to
illustrate the use of modals:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<title>Bootstrap Modals</title>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script type=“text/javascript”>
$(document).ready(function(){
www,engbookspdf.com
$(“#modal”).modal(‘show’);
});
</script>
</head>
<body>
<div class=“modal-dialog”>
<div class=“modal-content”>
<div class=“modal-header”>
<h4 class=“modal-title”>Verification</h4>
</div>
<div class=“modal-body”>
</div>
<div class=“modal-footer”>
</div>
www,engbookspdf.com
</div>
</div>
</div>
</body>
</html>
On running the above code, a pop up will be shown. The background will be fade so that
emphasis can be put on the modal as shown below:
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 11:
Accordion in Bootstrap
You may find that you have too much text to be represented on your webpage. You then
need to present text and hide the extra one which can be accessed by clicking on some
text. This can be achieved by use of accordions. Write the code below and run it:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<title>Bootstrap Accordion</title>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<style type=“text/css”>
.ls-example{
margin: 20px;
www,engbookspdf.com
}
</style>
</head>
<body>
<div class=“ls-example”>
<div class=“panel-heading”>
<h4 class=“panel-title”>
</h4>
</div>
<div class=“panel-body”>
<p>Bootstrap is just a combination of both HTML and CSS for web development.
Pages developed with bootstrap respond well on screens of different sizes . <a href=”#”
target=“_blank”>Read more.</a></p>
</div>
</div>
</div>
www,engbookspdf.com
<div class=“panel-heading”>
<h4 class=“panel-title”>
</h4>
</div>
<div class=“panel-body”>
<p>PHP is a language which is used to add functionality web pages. Buttons and other
components need to do something on click, and this is the purpose of PHP. <a href=”#”
target=“_blank”>Read more.</a></p>
</div>
</div>
</div>
<div class=“panel-heading”>
<h4 class=“panel-title”>
</h4>
</div>
www,engbookspdf.com
<div class=“panel-body”>
<p>It is one of the constituent components of bootstrap. For instance, most of bootstrap
functionalities have been achieved with CSS. Mainly used for adding styles to web pages.
Stands for Cascading Style Sheet <a href=”#” target=“_blank”>Read more.</a></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Once you run the above code, the following will be the output:
On clicking on any title, the others will collapse in and the description of the clicked one
will collapse out. You have then hidden the extra text which could not fit on the screen.
The amount of text used here doesn’t matter, as it be of any size. This shows how an
www,engbookspdf.com
accordion is important.
www,engbookspdf.com
www,engbookspdf.com
www,engbookspdf.com
Chapter 12:
Bootstrap Carousel
Sometimes after visiting websites, you just see some sliding images or text on the web
pages. In bootstrap, these sliding images and text can be created using the carousel. The
images and text can also be combined to slide together. This also helps in preserving the
available space on a web page and as well as making the web pages look beautiful. Write
and run the code below:
<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<link rel=“stylesheet”
href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css”>
<link rel=“stylesheet”
href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css”>
<script src=“https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script src=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js”>
www,engbookspdf.com
</script>
<style type=“text/css”>
h2{
margin: 0;
color: #666;
padding-top: 90px;
font-size: 52px;
.item{
background: #333;
text-align: center;
.carousel{
margin-top: 20px;
.bs-example{
margin: 20px;
</style>
www,engbookspdf.com
</head>
<body>
<div class=“bs-example”>
<ol class=“carousel-indicators”>
</ol>
<div class=“carousel-inner”>
<h2><img src=“images/i.jpg”></h2>
<div class=“carousel-caption”>
<h3></h3>
</div>
</div>
<div class=“item”>
www,engbookspdf.com
<h2><img src=“images/j.jpg”></h2>
<div class=“carousel-caption”>
<h3></h3>
</div>
</div>
<div class=“item”>
<h2><img src=“images/k.jpg”></h2>
<div class=“carousel-caption”>
<h3></h3>
</div>
</div>
</div>
</a>
</a>
www,engbookspdf.com
</div>
</div>
</body>
</html>
On running the above code, the output will be a sequence of sliding images. You will also
be providing with two means of sliding the next images manually. These will be two
www,engbookspdf.com
www,engbookspdf.com
Conclusion
Responsiveness is one of the current trends and emerging trends in web development. This
refers to how web pages behave on different devices with different display sizes. A
responsive design involves creating web pages which scroll well on all devices regardless
of their display size. Bootstrap is a good tool in this.
One can create a responsive website using bootstrap with a lot of ease and also quickly.
This explains why you should consider learning bootstrap. Complex and beautiful buttons
can be created with bootstrap. Unlike with pure HTML, tables created using bootstrap will
scroll well even on cell phones. Phones can also be created with amazing controls which
also respond automatically on different devices.
Three different types of layouts for forms are also available on forms, so you can choose
the layout of your choice. Lists are also supported in bootstrap. One can use these to create
amazing menus for their web pages, and then add links to these list items.
www,engbookspdf.com
Accordions are a component of bootstrap. If you want to represent too much text such that
you find it crowding the screen, use accordion to hide this text. To put emphasis on a
particular thing, a modal can be used. This will pop up on the screen and the user will
divert his or her attention to the modal. This should happen mostly when carrying out
dangerous actions.
You can also use bootstrap to slide your images and text if you need to do so. This is for
the purpose of saving on space or enhancing the beauty of your website.
www,engbookspdf.com