Module 4 Notes
Module 4 Notes
Module 4 Notes
Bengaluru
Autonomous College Under VTU
Department of CSE (Data Science)
MODULE 4
Bootstrap
By
Prof. Likhith S R
Assistant. Professor
Dept. of CSE(DS), NCET
Module - IV
Bootstrap: Bootstrap Scaffolding, Bootstrap CSS, Bootstrap Layout Components, Bootstrap
JavaScript Plugins, Using Bootstrap, Web services
Bootstrap Scaffolding
What Is Bootstrap?
Bootstrap is the most popular HTML, CSS and JavaScript framework for developing a
responsive and mobile friendly website. It is a front-end framework used for easier and faster
web development. It includes HTML and CSS based design templates for typography, forms,
buttons, tables, navigation, modals, image carousels and many others. It can also use
JavaScript plug-ins. It facilitates you to create responsive designs. It is absolutely free to
download and use.
Bootstrap is an open source product from Mark Otto and Jacob Thornton who, when it was initially
released, were both employees at Twitter. There was a need to standardize the frontend toolsets of
engineers across the company. In the launch blog post, Mark Otto introduced the project like this:
Since Bootstrap launched in August 2011, it has taken off in popularity. It has evolved from being
an entirely CSS-driven project to include a host of JavaScript plugins and icons that go hand in
hand with forms and buttons. At its base, it allows for responsive web design and features a robust
12-column, 940px-wide grid. One of the highlights is the build tool on Bootstrap’s website, where
you can customize the build to suit your needs, choosing which CSS and JavaScript features you
want to include on your site. All of this allows frontend web development to be catapulted forward,
building on a stable foundation of forward-looking design and development. Getting started with
Bootstrap is as simple as dropping some CSS and JavaScript into the root of your site.
For someone starting a new project, Bootstrap comes with a handful of useful elements. Normally,
when I start a project, I start with tools like Eric Meyer’s Reset CSS and get going on my web
project. With Bootstrap, you just need to include the bootstrap.css CSS
file and, optionally, the bootstrap.js JavaScript file into your website and you are ready to go.
The Bootstrap download includes three folders: css, js, and img. For simplicity, add these to the
root of your project. Minified versions of the CSS and JavaScript are also included. It is not
necessary to include both the uncompressed and the minified versions. For the sake of brevity, I
use the uncompressed version during development and then switch to the compressed version in
production.
• lg (for laptops and desktops - screens equal to or greater than 1200px wide)
The classes above can be combined to create more dynamic and flexible layouts.
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
</div>
• First; create a row (<div class="row">). Then, add the desired number of columns (tags with
appropriate .col-*-* classes). Note that numbers in .col-*-* should always add up to 12 for
each row.
• The following example shows how to get a three equal-width columns starting at tablets and
scaling to large desktops. On mobile phones or screens that are less than 768px wide, the
columns will automatically stack:
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-4">.col-sm-4</div>
</div>
• The columns will automatically stack on top of each other when the screen is less than
768px wide.
.col-sm-4 .col-sm-8
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-8">.col-sm-8</div>
</div>
The following code shows .span8 and .span4, which adds up to 12:
<div class="row">
<div class="span8">...</div>
<div class="span4">...</div>
</div>
Nesting Columns
To nest your content with the default grid, inside of a .span*, simply add a new .row with
enough .span* that it equals the number of spans of the parent container (see Figure 1-3):
<div class="row">
<div class="span9"> Level 1 of
column
<div class="row">
<div class="span6">Level 2</div>
<div class="span3">Level 2</div>
</div>
</div>
</div>
Scaffolding − Bootstrap provides a basic structure with Grid System, link styles, and background.
CSS − Bootstrap comes with the feature of global CSS settings, fundamental HTML elements
styled and enhanced with extensible classes, and an advanced grid system.
Components − Bootstrap contains over a dozen reusable components built to provide iconography,
dropdowns, navigation, alerts, pop-overs, and much more.
JavaScript Plugins − Bootstrap contains over a dozen custom jQuery plugins. You can easily
include them all, or one by one.
Customize − You can customize Bootstrap's components, LESS variables, and jQuery plugins to
get your very own version.
.
Using Bootstrap
There are two ways to start using Bootstrap on your own web site.
Download Bootstrap from getbootstrap.com
Include Bootstrap from a CDN
Downloading Bootstrap
If you want to download and host Bootstrap yourself, go to getbootstrap.com, and follow the
instructions there.
Bootstrap CDN
If you don't want to download and host Bootstrap yourself, you can include it from a CDN (Content
Delivery Network).
MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must also include
jQuery:
MaxCDN:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css
">
The following example shows the code for a basic Bootstrap page (with a responsive fixed width
container):
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.cs
s">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body></html>
The following example shows the code for a basic Bootstrap page (with a full width container):
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.cs
s">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body></html>
Bootstrap CSS
Headings
All six standard heading levels have been styled in Bootstrap with the <h1> at 36 pixels tall, and the
<h6> down to 12 pixels (for reference, default body text is 14 pixels tall). In addition, to add an inline
subheading to any of the headings, simply add <small> around any of the elements and you will get
smaller text in a lighter color. In the case of the <h1>, the small text is 24 pixels tall, normal font weight
(i.e., not bold), and gray instead of black:
h1 small {
font-size:24px;
font-weight:normal;line-height:1;
color:#999;
}
Emphasis
In addition to using the <small> tag within headings, as discussed above, you can also use it with
body copy. When <small> is applied to body text, the font shrinks to 85% of its original size.
Bold
To add emphasis to text, simply wrap it in a <strong> tag. This will add font- weight:bold; to
the selected text.
Italics
For italics, wrap your content in the <em> tag. The term “em” derives from the word “emphasis”
and is meant to add stress to your text.
Emphasis Classes
Along with <strong> and <em>, Bootstrap offers a few other classes that can be used to provide
emphasis. These could be applied to paragraphs or spans:
Abbreviations
The HTML <abbr> element provides markup for abbreviations or acronyms, like WWW or
HTTP. By marking up abbreviations, you can give useful information to browsers, spell
checkers, translation systems, or search engines. Boot‐ strap styles <abbr> elements with a light
dotted border along the bottom and reveals the full text on hover (as long as you add that text to
the <abbr> title attribute):
<abbr title="Real Simple Syndication">RSS</abbr>
Blockquotes
To add blocks of quoted text to your document—or for any quotation that you want to set apart
from the main text flow—add the <blockquote> tag around the text. For best results, and for line
breaks, wrap each subsection in a <p> tag. Bootstrap’s default styling indents the text and adds a
thick gray border along the left side. To identify the source
of the quote, add the <small> tag, then add the source’s name wrapped in a <cite> tag before closing
the </small>tag:
<blockquote>
<p>That this is needed, desperately needed, is indicated by the incredible
uptake of Bootstrap. I use it in all the server software I'm working on. And it
shows through in the templating language I'm developing, so everyone who
uses it will find it's "just there" and works, any time you want to do a Bootstrap
technique. Nothing to do, no libraries to include. It's as if it were part of the
hardware.
Same approach that Apple took with the Mac OS in 1984.</p>
<small>Developer of RSS, <cite title="Source Title">Dave Winer</cite>
</small>
</blockquote>
Code
There are two different key ways to display code with Bootstrap. The first is the <code> tag and
the second is the <pre> tag. Generally, if you are going to be displaying code inline, you should
use the <code> tag. But if the code needs to be displayed as a stand- alone block element or if it
has multiple lines, then you should use the <pre> tag:
<p>Instead of always using divs, in HTML5, you can use new elements like
<code><section></code>, <code><header></code>, and
<code><footer></code>. The html should look something like this:</p>
<pre>
<article>
<h1>Article Heading</h1>
</article>
</pre>
Tables
One of the favorite parts of Bootstrap is the nice way that tables are handled. I do a lot of work
looking at and building tables, and the clean layout is a great feature that’s included in
Bootstrap right off the bat. Table 2-1 lists the various elements supported by Bootstrap.
Tag Description
<thead> Container element for table header rows (<tr>) to label table columns
<tbody> Container element for table rows (<tr>) in the body of the table
<tr> Container element for a set of table cells (<td> or <th>) that appears on a single row
<th> Special table cell for column (or row, depending on scope and placement) labels. Must be used within a <thead>
<caption> Description or summary of what the table holds, especially useful for screen readers
If you want a nice, basic table style with just some light padding and horizontal dividers, add the
base class of .table to any table (see Figure 2-13). The basic layout has a top border on all of the
<td> elements:
<table class="table">
<caption>...</caption>
<thead>
<tr>
<th>...</th>
<th>...</th>
</tr>
</thead>
<tbody>
<tr>
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>
Hover table
Figure 2-16 shows the .table-hover class. A light gray background will be added to rows while
the cursor hovers over them.
Condensed table
If you add the .table-condensed class, as shown in Figure 2-17, row padding is cut in half to
condense the table. This is useful if you want denser information.
Forms
Another one of the highlights of using Bootstrap is the ability to create forms with ease. As a web
developer, styling forms is one of my least favorite tasks. Bootstrap makes it easy with the
simple HTML markup and extended classes for different styles of forms.
The basic form structure comes with Bootstrap; there is no need to add any extra helper classes (see
Figure 2-19). If you use the placeholder, keep in mind that it is only supported in newer browsers. In
older browsers, no placeholder text will be displayed:
<form>
<fieldset>
<legend>Legend</legend>
<label for="name">Label name</label>
<input type="text" id="name"
placeholder="Type something…">
<span class="help-block">Example block-level helptext
here.</span>
<label class="checkbox" for="checkbox">
<input type="checkbox" id="checkbox">
Web Programming(20CSI43) Module-4
</form>
Check me out
</label>
<button type="submit" class="btn">Submit</button>
</fieldset>
<form class="form-inline">
<input type="text" class="input-small" placeholder="Email">
<input type="password" class="input-small" placeholder="Password">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</form>
Horizontal form
Bootstrap also comes with a prebaked horizontal form; this one stands apart from the
others not only in the amount of markup, but also in the presentation of the form.
Traditionally you’d use a table to get a form layout like the one shown in Figure 2-22,
but Bootstrap manages to do it without using tables. Even better, if you’re using the
responsive CSS, the horizontal form will automatically adapt to smaller layouts by
stacking the controls vertically.
• Wrap any associated controls in a <div> with class .controls for proper alignment.
Buttons
One of the favorite features of Bootstrap is the way that buttons are styled. Dave Winer,
inventor of RSS and big fan of Bootstrap, has this to say about it:
I like to think that Bootstrap is unifying the Web and allowing a unified experience of
what an interface can look like across the Web. With the advent of Bootstrap, you can
usually spot the sites that have adopted it by the buttons that they use. A grid layout and
many of the other features fade into the background, but buttons, forms, and other
btn btn-primary Provides extra visual weight and identifies the primary action in a set of
buttons (blue)
btn btn-warning Indicates caution should be taken with this action (orange)
btn btn-link De-emphasizes a button by making it look like a link while maintaining
button behavior
Button Sizes
If you need larger or smaller buttons, simply add .btn-large, .btn-small, or .btn-mini to
links or buttons (see Figure 2-43):
<p>
For anchor elements, simply add the class of .disabled to the tag and the link will fade in
color, and lose the gradient (see Figure 2-45):
For a button, simply add the disabled attribute to the button (see Figure 2-46). This will
actually disable the button, so JavaScript is not directly needed:
Images
Images have three classes (see Figure 2-47) that can be used to apply some simple
styles: .img-rounded adds border-radius:6px to give the image rounded corners,
.img-circle makes the entire image round by adding border-radius:500px, and .img-
polaroid adds a bit of padding and a gray border:
Icons
Bootstrap bundles 140 icons into one sprite that can be used with buttons, links, navi‐
gation, and form fields. The icons are provided by GLYPHICONS; see Figure 2-48.
GLYPHICONS Attribution
Users of Bootstrap are fortunate to use the GLYPHICONS for free on Bootstrap projects.
The developers have asked that you link back to GLYPHICONS when practical.
Button groups
By using button groups combined with icons, you can create nice interface elements
with minimal markup (see Figure 2-49):
Navigation
When you are using icons next to a string of text, make sure to add a space to provide
the proper alignment of the image (see Figure 2-50). Navigation code will be covered
further in the next chapter.
Options
Right-align
Add .pull-right to a .dropdown-menu to right-align the dropdown menu to the parent
object:
Submenu
If you would like to add a second layer of dropdowns (see Figure 3-2), simply add
.dropdown-submenu to any <li> in an existing dropdown menu for automatic styling:
Button Groups
Button groups allow multiple buttons to be stacked together (see Figure 3-3). This is
useful when you want to place items like alignment buttons together. To create a button
group, simply wrap a series of anchors or buttons in a <div> that has .btn-group as a
class:
<div class="btn-group">
<button class="btn">1</button>
<button class="btn">2</button>
<button class="btn">3</button>
</div>
<div class="btn-group">
<button class="btn btn-danger">Danger</button>
<button class="btn btn-danger dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
You can use the dropdowns with any button size: .btn-large, .btn, .btn-small, or
.btn-mini. Figure 3-7 shows several examples of different button sizes.
<div class="btn-group">
<button class="btn">Action</button>
Dropup Menus
Menus can also be built to drop up rather than down (see Figure 3-9). To make this
change, simply add .dropup to the .btn-group container. To have the button pull up from
Navigation Elements
Bootstrap provides a few different options for styling navigation elements. All of them
share the same markup and base class, .nav.
Bootstrap also provides a helper class, .active. In principle, it generally adds distinction to
the current element and sets it apart from the rest of the navigation elements. You can
add this class to the home page links or to the links of the page that the user is
currently on.
To create a tabbed navigation menu (see Figure 3-10), start with a basic unordered list
with the base class of .nav and add .nav-tabs:
To turn the tabs into pills (see Figure 3-11), use .nav-pills instead of .nav-tabs:
Disabled class
For each of the .nav classes, if you add the .disabled class, it will create a gray link that also
disables the :hover state (see Figure 3-12):
The link is still clickable unless the href is removed with JavaScript or some other method.
Stackable Navigation
Both tabs and pills are horizontal by default. To make them appear vertically stacked,
just add the .nav-stacked class. See Figures 3-13 and 3-14 for examples of verticaly
stacked tabs and pills.
Dropdowns
Navigation menus share a similar syntax with dropdown menus (see Figure 3-15). By
default, you have a list item that has an anchor working in conjunction with some data-
attributes to trigger an unordered list with a .dropdown-menu class:
Pagination
Bootstrap handles pagination like a lot of other interface elements, an unordered list,
with wrapper a <div> that has a specific class that identifies the element. In the basic form,
adding .pagination to the parent <div> creates a row of bordered links. Each of the list
items can be additionally styled by using the .disabled or .active class. See Figures 3-29
and 3-30 for examples of this.
<div class="pagination">
<ul>
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
Dept. of CSE(Data Science), NCET 32 2021-22
Web Programming(20CSI43) Module-4
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
</div>
Pager
If you need to create simple pagination links that go beyond text, the pager can work
<ul class="pager">
<li><a href="#">Previous</a></li>
<li><a href="#">Next</a></li>
</ul>
To left- or right-align the links, you just need to add the .previous and .next class as to
the list items (see Figure 3-33). Also, like .pagination in Figure 3-31, you can add the
.disabled class for a muted look.
<ul class="pager">
<li class="previous">
<a href="#">← Older</a>
</li>
<li class="next">
<a href="#">Newer →</a>
</li>
</ul>
Labels
Labels are great for offering counts, tips, or other markup for pages. They’re another of
my favorite little Bootstrap touches. Figure 3-34 shows some labels that can be used.
<span class="label">Default</span>
<span class="label label-success">Success</span>
<span class="label label-warning">Warning</span>
<span class="label label-important">Important</span>
<span class="label label-info">Info</span>
<span class="label label-inverse">Inverse</span>
Badges
Badges are similar to labels; the primary difference is that the corners are more rounded.
The colors of badges reflect the same classes as labels (see Figure 3-35).
<span class="badge">1</span>
<span class="badge badge-success">2</span>
<span class="badge badge-warning">4</span>
<span class="badge badge-important">6</span>
Dept. of CSE(Data Science), NCET 35 2021-22
Web Programming(20CSI43) Module-4
<span class="badge badge-info">8</span>
<span class="badge badge-inverse">10</span>
Modal
A modal is a child window that is layered over its parent window (see Figure 4-1).
Typically, the purpose is to display content from a separate source that can have some
interaction without leaving the parent window. Child windows can provide informa‐
tion, interaction, or more. I use them as a window for holding slideshows and login/
registration information. The modal plugin is probably one of my favorite Bootstrap
features.
To invoke the modal window, you need to have some kind of a trigger. Normally I use a
button or a link. If you look in the code below, you will see that in the <a> tag, the
href="myModal" is the target of the modal that you want to load on the page. This code
allows you to create multiple modals on the page and then have different triggers for
each of them. Now, to be clear, you don’t load multiple modals at the same time, but you
can create many on the page to be loaded at different times.
There are three classes to take note of in the modal. The first is .modal, which is simply
identifying the content of the <div> as a modal. The second is .hide, which tells the
browser to hide the content of the <div> until we are ready to invoke it. And last, the
.fade class. When the modal is toggled, it will cause the content to fade in and out.
<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch
demomodal</a>
Collapse
The collapse plugin makes it easy to make collapsing divisions of the page (see
Figure 4-12). Whether you use it to build accordion navigation or content boxes, it
allows for a lot of content options.
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-
parent="#accordion2"href="#collapseTwo">
Collapsible Group Item #2
</a>
</div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner"> Anim
pariatur cliche...
</div>
</div>
</div>
</div>
...
You can also use the data attributes to make all content collapsible:
A web service is a set of open protocols and standards that allow data to be exchanged
between different applications or systems. Web services can be used by software programs
written in a variety of programming languages and running on a variety of platforms to
exchange data via computer networks such as the Internet in a similar way to inter-process
communication on a single computer.
A root element known as the element is required in every SOAP document. In an XML
document, the root element is the first element. The “envelope” is separated into two
halves. The header comes first, followed by the body. The routing data, or information
that directs the XML document to which client it should be sent to, is contained in the
header. The real message will be in the body.
The UDDI registry will hold the required information for the online service, just like a
telephone directory has the name, address, and phone number of a certain individual. So
that a client application may figure out where it is.