Unit 2
Unit 2
UNIT IV BootStrap
Introduction:
Bootstrap is a powerful front-end framework for faster and easier web development.
It includes HTML and CSS based design templates for creating common user interface
components like forms, buttons, navigations, dropdowns, alerts, modals, tabs, accordions,
carousels, tooltips, and so on.
Bootstrap gives you ability to create flexible and responsive web layouts with much less
efforts.
Bootstrap was originally created by a designer and a developer at Twitter in mid-2010.
Before being an open-sourced framework, Bootstrap was known as Twitter Blueprint.
Importance of Bootstrap
There are lot more things that can be done with Bootstrap:
Apart from the above list there are many other interesting things that can be done with Bootstrap
Drawbacks of Bootstrap
Styles are verbose and can lead to lots of HTML output that's not perfectly semantic.
JavaScript is tied to jQuery (it's by the far the most common javascript library though and
the plugins can just as easily be left unused).
Can require lots of overriding styles or rewriting their files if you have lots of
customizations or want to deviate from Bootstrap structure.
Websites can start to look the same if you don't customize the styles and colors much.
3
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
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.
Struct:2
<div class = "container">
<div class = "row">
<div class = "col-*-*"></div>
<div class = "col-*-*"></div>
</ div>
<div class = "row">...</div>
</ div>
<div class = "container">
....
</div >
Grid Classes
Bootstrap includes predefined grid classes for quickly making grid layouts for different types of
devices like cell phones, tablets, laptops and desktops, etc
The Bootstrap grid system has four classes:
Example
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: Three Equal Columns
</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
(1) equal colomn
<!--Row with three equal columns-->
<div class="row">
<div class="col-md-4">!--Column left--</div>
<div class="col-md-4">--Column middle--</div>
<div class="col-md-4">--Column right--</div>
</div>
<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-
8</div> </div>
<div class="row">
<div class="col-sm-2" style="background-color:orange;">.col-sm-2</div>
<div class="col-sm-4" style="background-color:green;">.col-sm-4</div>
<div class="col-sm-*" style="background-color:yellow;">.col-sm-6</div>
</div>
</div>
7
Bootstrap Tables
Bootstrap provides a clean layout for building tables and you can greatly improve the
appearance of table
A basic Bootstrap table has a light padding and only horizontal dividers.
Table elements supported by Bootstrap are :
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>
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
<html>
<head>
<title>Bootstrap Tables</title>
<link rel="stylesheet" ref="bootstrap.min.css">
<script src="jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
</head>
<body>
<table class = "table">
<caption>Basic Table Layout</caption>
<thead>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>Abhay</td>
<td>80</td>
</tr>
<tr>
<td>Sachin</td>
<td>75</td>
</tr>
</tbody>
</table>
</body>
</html>
9
Bootstrap Form-control
HTML forms are the integral part of the web pages and applications, but styling the
form controls manually one by one with CSS are often boring and tedious.
Bootstrap makes it easy with the simple HTML markup and extended classes for different
styles of forms controls like labels, input fields, selectboxes, textareas, buttons, etc. through
predefined set of classes.
Form controls automatically receive some global styling with Bootstrap: All textual
<input>, <textarea>, and <select> elements with class .form-control have a width of 100%.
Bootstrap provides three different types of form layouts:
1. Vertical Form (default form layout)
2. Horizontal Form
3. Inline Form
.form-group Any group of form controls Use with any block-level element
like <fieldset> or <div>
.form-control : Textual inputs text, password, datetime-
it make input local, date, month, time,week, number,
element full-width email, url,search, tel, color
Select menus multiple, size
Textareas N/A
.form-control-file File inputs file
.checkbox Checkboxes N/A
.checkbox-inline
.radio Radio N/A
.radio-inline
.input-lg for bigger input elements
than default-size (used with
input elemnt)
.input-sm for smaller input elements
than default-size
10
<html>
<head>
<title>Bootstrap Example</title>
<link rel="stylesheet" href="bootstrap.min.css">
</head>
<body>
<div>
<h2>Vertical (basic) form</h2>
<form>
<div class=”form-group”>
<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>
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" placeholder="Enter email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" placeholder="Enter password">
</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>
12
Example: 1
<form class="form-inline">
<div class="form-group">
<label for="name1"> name </label>
<input type="text" class="form-control" id="name1" placeholder="name"/>
</div>
</form>
output
Example 2
<form class="form-inline" >
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control"
id="email"> </div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control"
id="pwd"> </div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
13
Bootstrap Input
Bootstrap supports all the HTML5 input types: text, password, datetime, datetime-local,
date, month, time, week, number, email, url, search, tel, and color.
The following example contains two input elements; one of type text and one of type password:
<div class="form-group">
<label for="usr">Name:</label>
<input type="text" class="form-control" id="usr">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control"
id="pwd"> </div>
Bootstrap Textarea
The following example contains a textarea:
<div class="form-group">
<label for="comment">Comment:</label>
<textarea class="form-control" rows="5"
id="comment"></textarea> </div>
Bootstrap Checkboxes
The following example contains three checkboxes. The last option is disabled
<div class="checkbox">
<label><input type="checkbox" value="">Option 1</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="">Option 2</label>
</div>
<div class="checkbox disabled">
<label><input type="checkbox" value="" disabled>Option 3</label>
</div>
Use the .checkbox-inline class if you want the checkboxes to appear on the same line
14
<div class="radio">
<label><input type="radio" name="optradio" checked>Option 1</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio">Option 2</label>
</div>
<div class="radio disabled">
<label><input type="radio" name="optradio" disabled>Option 3</label>
</div>
Use the .radio-inline class if you want the radio buttons to appear on the same line
<div class="form-group">
<label for="sel1">Select list:</label>
<select class="form-control" id="sel1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
Bootstrap Alerts
Bootstrap provides an easy way to create predefined alert messages.
You can add a basic alert by creating a wrapper <div> and adding a class of .alert and one
of the four contextual classes:
Alerts are created with the .alert class, followed by one of the contextual classes.alert-
success, .alert-info, .alert-warning, .alert-danger, .alert-primary, .alert-secondary,
.alert-light or .alert-dark
The following example demonstrates this −
<!DOCTYPE html>
<html>
<head>
<title>Try v1.2 Bootstrap Online</title>
<link href=”bootstrap.min.css" rel="stylesheet">
</head>
<body>
</body>
</html>
16
Closing Alerts
To build a dismissal alert −
Add a basic alert by creating a wrapper <div> and adding a class of .alert and one of the
contextual classes
Also add optional .alert-dismissable to the above <div> class.
Add a close button.
The following example demonstrates this −
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Success!</strong> Indicates a successful or positive action.
</div>
Alert Links
To get links in alerts
Add a basic alert by creating a wrapper <div> and adding a class of .alert and one of the
contextual classes.
Use the .alert-link utility class to quickly provide matching colored links within any alert.
The following example demonstrates this −
Animated Alerts
The .fade and .show classes adds a fading effect when closing the alert message
Example-
Bootstrap 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 button CSS provides the quick and easy
way to create and customize the buttons.
Button Styles
Different classes are available in Bootstrap for styling and state Button styles can be applied to any
element.
However, it is applied normally to the <a>, <input>, and <button> elements for the best rendering.
Class Description
Button State
A button can be set to an active (appear pressed) or a disabled (unclickable) state:
Active Primary Disabled Primary
Anchor element Use .active class to <a> buttons to show that it is activated.
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.
classes used to make button element and anchor element disabled −
Element Class
Button groups allow multiple buttons to be stacked together on a single line. This is useful when
you want to place items like alignment buttons together.
You can add on optional JavaScript radio and checkbox style behavior with Bootstrap
Button Plugin.
Following table summarizes the important classes Bootstrap provides to use button groups −
Class Description Code Sample
.btn-toolbar This helps to combine sets <div class = "btn-toolbar" role = "toolbar">
of <div class = "btn-group"> <div class = "btn-group">...</div>
into a <div class = "btn- <div class = "btn-group">...</div>
toolbar"> for more complex </div>
components.
</div>
21
Button Toolbar
The following example demonstrates the use of class .btn-toolbar discussed in the above table −
<div class = "btn-toolbar" role = "toolbar">
</div>
Button Size
The following example demonstrates the use of class .btn-group-* discussed in the above table −
<div class = "btn-group btn-group-lg">
<button type = "button" class = "btn btn-default">Button 1</button>
<button type = "button" class = "btn btn-default">Button 2</button>
<button type = "button" class = "btn btn-default">Button 3</button>
</div>
Nesting
You can nest button groups within another button group i.e, place a .btn-group within another
.btn-group . This is done when you want dropdown menus mixed with a series of buttons.
<div class = "btn-group">
<button type = "button" class = "btn btn-default">Button 1</button>
<button type = "button" class = "btn btn-default">Button 2</button>
</div>
The following example demonstrates the use of class .btn-group-vertical discussed in the above
table −
<div class = "btn-group-vertical">
<button type = "button" class = "btn btn-default">Button 1</button>
<button type = "button" class = "btn btn-default">Button 2</button>
</div>