Unit 2 Bootstrap
Unit 2 Bootstrap
• Bootstrap is the most popular HTML, CSS, and JavaScript framework for
developing responsive, mobile-first web sites.
• Bootstrap is a front-end framework for faster and easier web development
• Bootstrap includes HTML and CSS based design templates for typography, forms,
buttons, tables, navigation, modals, image carousels and many other, as well as
optional JavaScript plugins
• Bootstrap also gives you the ability to easily create responsive designs
• It is Mobile first approach.
• Bootstrap is free to download and use.
Advantages of Bootstrap
• Save lots of time — You can save lots of time and efforts using the Bootstrap
predefined design templates and classes and concentrate on other development work.
• Responsive features — Using Bootstrap you can easily create responsive websites
that appear more appropriately on different devices and screen resolutions without
any change in markup.
• Consistent design — All Bootstrap components share the same design templates and
styles through a central library, so the design and layout of your web pages will be
consistent.
• Easy to use — Bootstrap is very easy to use. Anybody with the basic working
knowledge of HTML, CSS and JavaScript can start development with Bootstrap.
• Compatible with browsers — Bootstrap is created with modern web browsers in
mind and it is compatible with all modern browsers such as Chrome, Firefox, Safari,
Internet Explorer, etc.
• Open Source — And the best part is, it is completely free to download and use.
• Platform Independence: It creates Platform-independent web-pages
• It works with any editor.
• It works with any server side technology.
1
<link rel="stylesheet" href="bootstrap.min.css"> link to bootstrap folder.
The columns will re-arrange automatically depending on the output device. The
figure 1 shows grid structure.
span span span span span span span span span span span span
1 1 1 1 1 1 1 1 1 1 1 1
span 4 span 8
span 6 span 6
span 12
Grid Classes
• The Bootstrap grid system support following classes:
Examples:
How to get a three equal-width columns starting starting at tablets and scaling to large
desktops. On mobile phones, the columns will automatically stack:
2
Three Equal Columns
<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>
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
</head>
<body>
<div">
<h1>Hello World!</h1>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="col-sm-4" style="background-color:lavender;">.col-sm-4</div>
<div class="col-sm-4" style="background-color:lavenderblush;">.col-sm-4</div>
<div class="col-sm-4" style="background-color:lavender;">.col-sm-4</div>
</div>
</div>
</body>
</html>
Three column
3
Two column
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-8">.col-sm-8</div>
</div>
Two equal column
<div class="container">
<!--Row with two equal columns-->
<div class="row">
<div class="col-sm-6">--Column left--</div>
<div class="col-sm-6">--Column right--</div>
</div>
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-8">.col-sm-8</div>
</div>
{{
Supported Table elements:
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.
4
<td> Default table cell.
<th> Special table cell for column (or row, depending on scope and
placement) labels. Must be used within a <thead>
}}
Bootstrap <table> Classes
Class Description
.table Adds basic styling (light padding and only horizontal dividers) to
any <table>
.table-striped Adds zebra-striping to any table row within <tbody>. You can
create table with alternate background like zebra-stripes
.table-condensed Makes table more compact by cutting cell padding in half and save
the space
Class Description
Example:
Creating a Simple Table with Bootstrap
A basic Bootstrap table has a light padding and only horizontal dividers.
5
The .table class adds basic styling to a table:
<table class = "table">
<caption>Basic Table Layout</caption>
<thead>
<tr>
<th>Name</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>jmp</td>
<td>vadodara</td>
</tr>
<tr>
<td>abc</td>
<td>surat</td>
</tr>
</tbody>
</table>
</body>
</html>
output
Basic Table Layout
Name City
jmp vadodara
abc surat
<thead>
<tr>
6
<th>Product</th>
<th>Payment Date</th>
</tr>
</thead>
<tbody>
<tr class = "active">
<td>Product1</td>
<td>Pending</td>
</tr>
<td>Delivered</td>
</tr>
<td>Declined</td>
</tr>
</tbody>
</table>
• Bootstrap colour classes are used to apply colour to element depending on their
context.
Example:
Following line display light text on danger background colour.
7
<p class="bg-danger text-light "> light text on danger background color </p>
Example:
The following example demonstrates various Bootstrap Alerts classes.
<body>
<div class="alert alert-warning" >
This is a warning alert
</div>
Example:
The following example creates closing alert box. when you click close button,
this the alert box will disappear/ closed. "×” indicate x sign.
9
Animated alert
• It is possible to give animation when closing the alert message.
The fade and in classes are used to adds a fading effect.
• Following line create animated alerts.
• Bootstrap form controls are used to customize from. It allows to give different styles
of forms controls like labels, buttons, input, select, checkbox, textarea, etc.
Classes Description
form-group group form controls
form-control make element width is 100%
form-horizontal create horizontal form
form-inline create inline form
form-control-file for File inputs
form-check, for Checkboxes and radios
form-check-
inline
input-lg set height bigger than default-size
input-sm set height smaller than default-size
<body>
<div>
<h2>Vertical (basic) form</h2>
<form>
<div>
10
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter
password">
</div>
(ii)
Horizontal Form Layout
In horizontal form layout labels are right aligned and floated to left to make them
appear on the same line as form controls.
To create a form that uses the horizontal layout, do the following −
Example:
<body>
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2"> User id:</label>
<div class="col-sm-10">
<input type="text" class="form-control">
</div>
</div>
11
<div class="form-group">
<label class="control-label col-sm-2"> Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default"> Submit</button>
</div>
</div>
</form>
</body>
Output:
Example:
Following code display Inline Form layout.
<body>
<form class="form-inline">
<div class="form-group">
<label>User Id:</label>
<input type="text" class="form-control">
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" class="form-control">
</div>
</body>
output
12
4 Working with buttons
4.1 Buttons
Buttons are the integral part of a website and application. They are used for various
purposes like, submit or reset an HTML form, performing interactive actions such as
showing or hiding something on a web page on click of the button, etc. The
Bootstrap buttons classes apply different styles to buttons.
Button Styles
{{it is applied normally to the <a>, <input>, and <button> elements for the best
rendering.}}
Bootstrap support following classes to apply styles to button:
Button Class Description
btn btn-default Default gray button with gradient.
13
Class Description
Button State
• A button can be set to an active (appear pressed) or a disabled (unclickable) state:
(i) Active Primary (ii)Disabled Primary
Element Class
Anchor element Use .active class to <a> buttons to show that it is activated.
14
ii)Disabled State
• Sometimes we need to disable a button for certain reasons like, a user in case is
not eligible to perform this particular action, or we want to ensure that user should
performed all other required actions before proceed to this particular action.
• It is unclickable
• When you disable a button, it will fade in color by 50%, and lose the gradient.
Element Class
Class Description
Example:
example of class btn-group
<body>
<div class = "btn-group">
Output:
Button will display as shown in figure:
= = == = = == = =
5 Bootstrap: media object
Bootstrap provides an easy way to align media objects (like images or videos) to the
left or to the right of some content. This can be used to display blog comments,
tweets and so on
5.1 Images
• Using the Bootstrap built-in classes you can easily style images such as making the
round cornered or circular images, or give them effect like thumbnails.
• Image can be displayed in circle, thumbnail or Rounded Corners.
• Bootstrap provides three classes that can be used to apply some simple styles to images:
class description
img-circle display image in circle.
img-rounded display image in Rounded corners.
img-thumbnail gives effect of Thumbnail. It adds padding and a gray border. It
is also helpful in creating images or videos gallery.
Example:
Output:
Responsive Images
• in Bootstrap you can make the images responsive too. Images come in all sizes.
Responsive images automatically adjust to fit the size of the screen.
Example:
16
<img class="img-responsive" src="myphoto.jpg" >
• Bootstrap gives simple way to align media objects such as images or videos,
so media objects appear to the left (left-aligned) or to the right (right-aligned)
of some content.
• This type of alignment is necessary while writing blog comments, tweets and
so on. The media object is used to make the code for creating this type of
alignment shorter.
class description
media Define media group
media-body Define body for media object
media-object Define media object
media-heading Set heading
media-left Set media object left align to text
media-right Set media object right align to text
media-top Set media object align to top
media-bottom Set media object align to bottom
media-middle Set media object align to middle
Media-list Define media list
<div class="container">
<!-- Left-aligned -->
<div class="media">
<div class="media-left">
<img class="media-object" src="image1.jpg" height=100 width=100>
</div>
<div class="media-body">
<h3 class="media-heading"> demo fo Media object:left align</h3>
<p> Concept of web technology html css javascript, Concept of web
technology html css javascript</p>
</div>
</div>
</div>
17
Example:
Following code show how media object left & right align.
<body>
<div class="container">
<!-- Left-aligned -->
<div class="media">
<div class="media-left">
<img class="media-object" src="myphoto.jpg" height=100 width=100>
</div>
<div class="media-body">
<h3 class="media-heading"> demo of Media object:left align</h3>
<p> This is demo of media object left alignment. This is demo of media
object left alignment</p>
</div>
</div>
<hr>
<!-- Right-aligned -->
<div class="media">
<div class="media-body">
<h3 class="media-heading"> Media object: right align</h3>
<p> This is demo of media object right alignment. This is demo of media
object right alignment</p>
</div>
<div class="media-right">
<img class="media-object" src="myphoto.jpg" height=100 width=100>
</div>
</div>
</div>
</body>
Output:
18
Media objects can also be nested inside other media object. It can be very useful for
creating comment threads in a blog post
Example:
Following example shows nesting of media object.
<body>
<h2>Nested Media Objects</h2>
<div class="media">
<div class="media-left">
<img src="img_avatar1.png" class="media-object" style="width:45px">
</div>
<div class="media-body">
<h4 class="media-heading">XYZ: Posted on 3/6/21</h4>
<p>How are you? Learning is great!!!</p>
</div>
</div>
</div>
</div>
</div>
</body>
Output:
6. Pagination
19
Active page
Example
</ul>
<p> pagination smaller size: </p>
<ul class="pagination pagination-sm">
<li class="active"> <a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
</ul>
20
<li><a href="#">4</a></li>
</ul>
Output:
21