Web Development Semester Note 6
Web Development Semester Note 6
2021
BASIC OVERVIEW
[Link] Documentation Starter template copy the code
build html file paste the code open in Live Server(VS code)
[Link] Components copy & paste the other content in html file.
| What is Bootstrap |
- Bootstrap is a free front-end framework for faster and easier web development
- Bootstrap is directed to create responsive designs.
- It contains HTML, CSS and JavaScript-based design templates for typography, forms, buttons,
navigation, and other interface components.
VERSIONS
Bootstrap 3 Bootstrap 4 Bootstrap 5
2013 2018 2021
PAGE 1
| Create the Basic Web Page with Bootstrap 5 |
<html lang="en">
<head>
<title>Bootstrap 5</title>
<meta charset="utf-8">
</head>
<body>
PAGE 2
<div class="container-fluid">
<h1>First Bootstrap Page</h1>
<p>This part is inside a .container-fluid class.</p>
<p>The .container-fluid class provides a fixed width container, covering
the entire width of the viewport. </p>
</div>
</body>
</html>
PAGE 3
| Bootstrap Grids |
The Bootstrap grid is a powerful, mobile-first, flexbox-based (layout) system for building responsive
layouts using a 12-column structure.
Key Concepts
Containers: Content must be placed within a .container (fixed width with padding)
or .container-fluid (full width) for proper alignment and padding.
Rows: Rows (.row) are covers for columns and use the columns' padding.
Columns: Content is placed within columns (.col-*). A row can contain up to 12 columns.
Column widths are set in percentages and adapt to the screen size.
Example :
<div class="container">
<div class="row">
<div class="col-sm-4">Column 1</div>
<div class="col-sm-4">Column 2</div>
<div class="col-sm-4">Column 3</div>
</div>
</div>
PAGE 4
| Bootstrap Table |
Tables automatically adjust to different screen sizes.
Allows showing/hiding specific columns, headers, and footers, and applying various styling
options like striped rows, borders, and hover effects.
Supports multiple languages.
Includes simple column sorting, single/multiple row selection (with radio or checkboxes), and
searching/filtering capabilities.
A basic Bootstrap 5 table has a light padding and horizontal dividers.
The .table class adds basic styling (light padding and horizontal dividers) to a table.
Example :
PAGE 5
Striped rows
Use .table-striped to add zebra-striping to any table row within the <tbody>.
Example :
Hover rows
Add .table-hover class adds a hover effect (grey background color) on table rows, to enable a hover
state on table rows within a <tbody>.
Dark Table
The .table-dark class adds a black background to the table.
PAGE 6
Borderless Table
Add .table-borderless for a table without borders.
Table Color
It can be used to color the whole table (<table>), the table rows (<tr>) or table cells (<td>).
PAGE 7
Responsive Table
The .table-responsive class allows to be scrolled horizontally when needed (when it is too long
horizontally).
Example :
<div class="table-responsive-lg">
<table class="table">
...
</table>
</div>
PAGE 8
| Responsive Images |
Images adapt gracefully to different screen sizes, resolutions, and device capabilities.
Images in Bootstrap are made responsive with .img-fluid. This applies max-width: 100%; and height:
auto; to the image so that it scales with the parent element.
This means the image will never be wider than its container, and its height will adjust proportionally.
Combine .img-fluid with other classes for enhanced styling and layout control:
PAGE 9
| Jumbotron |
The jumbotron is a built-in, lightweight, flexible component for showcasing highlight style content.
To grab the user's attention immediately with a large, padded box, often containing a headline, a brief
description, and a call-to-action button.
It indicates a big box for calling extra attention to some special content or information.
A jumbotron is displayed as a grey box with rounded corners. It also enlarges the font sizes of the text
inside it.
Use inside <div> with class .jumbotron . To make it full-width without rounded corners,
the .jumbotron-fluid class is used.
.jumbotron-fluid This is a modified jumbotron that occupies the entire horizontal space of its
parent.
Example :
| Page Header |
To provide a simple section divider for page headings, adding extra space around the heading and a
subtle horizontal line below it.
It was a lightweight styling that primarily affected the spacing and appearance of an <h1> tag within a
container.
The .page-header class adds a horizontal line under the heading (adds some extra space around the
element).
PAGE 10
Example :
<div class="container">
<div class="page-header">
<h1>Page Header</h1>
</div>
</div>
| Buttons |
Bootstrap provides a set of predefined classes for creating stylish, responsive, and functional buttons.
All Bootstrap buttons require a base class, .btn, combined with a modifier class that defines the visual
style, or size.
Button Color :
Example :
PAGE 11
<a class="btn btn-primary" href="#" role="button">Link</a>
<button class="btn btn-danger" type="submit">Button</button>
<input class="btn btn-warning" type="button" value="Input">
<input class="btn btn-dark" type="submit" value="Submit">
<input class="btn btn-light" type="reset" value="Reset">
Button Outline
class : .btn-outline-* remove all background images and colors on any button.
Button Sizes
i. Large .btn-lg
ii. Normal
iii. Small .btn-sm
iv. XSmall .btn-xs
Example:
Example :
Active/Disabled Buttons
PAGE 12
An active button appears pressed (with a darker background, border, and an inset shadow).
A disabled button is un-clickable and appears visually inactive (usually grayed out).
class .active and the attribute aria-pressed="true" or “false” (for a select/deselect button, or
active/inactive button).
Example :
<button type="button" class="btn btn-primary active" aria-pressed="true">Active
Button</button>
<button type="button" class="btn btn-primary disabled" aria-
pressed="true">Disabled Button</button>
class .active and the attribute role=”button” , aria-pressed="true" or “false” (for a select/deselect
button, or active/inactive button).
Example:
| Button Groups |
A Bootstrap button group is used to group a series of buttons together on a single line or, stack them
vertically.
It is used with class .btn-group within <div> tag to create a button group.
Also it can add class .btn-group-* to size all buttons in a button group.
Example 1 :
<div class="btn-group">
<button type="button" class="btn btn-primary">HTML</button>
<button type="button" class="btn btn-primary">CSS</button>
<button type="button" class="btn btn-primary">JavaScript</button>
</div>
Example 2 :
PAGE 13
<div class="btn-group btn-group-sm" >
<button type="button" class="btn btn-primary">HTML</button>
<button type="button" class="btn btn-primary">CSS</button>
<button type="button" class="btn btn-primary">JavaScript</button>
</div>
For Vertical button groups: It is used the .btn-group-vertical class instead of .btn-group to
stack buttons in a vertical column.
Example 3 :
For Justified button groups: To span the entire width of the screen, It is used the
.btn-group-justified class.
Example 4 :
PAGE 14
Checkbox and Radio Button Groups :
Bootstrap's button styles can be used to create checkbox or radio-style toggling behavior.
Example 5 :
Example 6 :
PAGE 15
| Dropdown Menus |
A dropdown menu is a toggleable menu that allows the user to choose one value from a predefined
list.
1. The structure for a basic dropdown involves the menu within an element that has
the .dropdown class within <div> tag.
2. Contains a button or link with .dropdown-toggle class.
3. <ul> with .dropdown-menu class that holds the menu items (<li> with .dropdown-item).
4. It can also include separators using .dropdown-divider class.
5. data-bs-toggle="dropdown" Attribute to activate JavaScript functionality.
Example :
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu"
data-bs-toggle="dropdown" >
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu">
<li><a class="dropdown-item" href="#">Google</a></li>
<li><a class="dropdown-item" href="#">Chrome</a></li>
<li><a class="dropdown-item" href="#">Safari</a></li>
</ul>
</div>
| Badges |
Bootstrap badges are small, highly customizable visual components.
It used to display an indicator or count a number, such as the number of unread notifications, new
items, or a status label.
To create a basic badge, .badge class is used.
The badge will automatically scale to match the font size of its parent element.
Example 1:
<h1> heading 1 <span class="badge bg-secondary">New</span></h1>
<h2> heading 2 <span class="badge bg-secondary">New</span></h2>
<h3> heading 3 <span class="badge bg-secondary">New</span></h3>
PAGE 16
Badges can be used as part of links or buttons to provide a counter.
Example 2:
<button type="button" class="btn btn-primary">
Notifications <span class="badge bg-secondary">4</span>
</button>
Example 3 :`
<button type="button" class="btn btn-primary position-relative" >
Notifications <span class="badge position-absoulte bg-secondary">99+
<span class="badge position-absoulte bg-secondary">unread</span>
</span>
</button>
| Labels |
Labels are used to provide additional informations.
.label class is used with following classes; .label-default, .label-primary, .label-success, .label-info, .label-
warning or .label-danger, within a <span> element to create a label.
Example :
PAGE 17
| List |
The most basic list group is an unordered list with list items and the proper classes.
An <ul> element with class .list-group, and <li> elements with class .list-group-item.
Example 1:
<ul class="list-group">
<li class="list-group-item">item 1</li>
<li class="list-group-item">item 2</li>
<li class="list-group-item">item 3</li>
</ul>
Example 2:
<ul class="list-group">
<li class="list-group-item active">item 1</li>
<li class="list-group-item disabled">item 2</li>
<li class="list-group-item">item 3</li>
</ul>
To create a list group with linked items, use <div> instead of <ul> and <a> instead of <li>.
Example 3:
<div class="list-group">
<a href="#" class="list-group-item">item 1</a>
<a href="#" class="list-group-item">item 2</a>
<a href="#" class="list-group-item">item 3</a>
</div>
Example 4:
<ul class="list-group">
<li class="list-group-item list-group-item-danger">item 1</li>
<li class="list-group-item list-group-item-success">item 2</li>
</ul>
PAGE 18
| Navigation Bar |
A navigation bar is a navigation header that is placed at the top of the page.
Class Purpose
PAGE 19
Example :
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-
target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle
navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-
disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
PAGE 20
| Forms |
Bootstrap forms provide responsive, and stylish form elements such as input boxes, buttons,
checkboxes, radio buttons, text areas, select menus, and validation messages.
<input>, <textarea>, and <select> elements with class .form-control have a width of 100%.
Bootstrap provides three types of form layouts:
Vertical form (by default)
Horizontal form
Inline form
Use labels and form controls in <div class="form-group"> , add class .form-control to all
textual <input>, <textarea>, and <select> elements.
<form>
<div class="form-group">
<label for="Email1">Email address</label>
<input type="email" class="form-control" id="Email1" placeholder="Enter email">
</div>
<div class="form-group">
<label for="Password1">Password</label>
<input type="password" class="form-control" id="Password1"
placeholder="Password">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="Check1">
<label class="form-check-label" for="Check1">Check out</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
In an inline form, all of the elements are inline, left-aligned, and the labels are side by side.
class .form-inline is used within the <form> element.
Example 2:
PAGE 21
<input type="password" class="form-control" id="Password1"
placeholder="Password">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="Check1">
<label class="form-check-label" for="Check1">Check out</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
A horizontal form means that the labels are aligned next to the input field (horizontal) on large
and medium screens. Class .form-horizontal is used with the <form> element and
class .control-label is used with all <label> elements.
Class Purpose
PAGE 22
valid-feedback / Validation messages. Shown when a field is accepted or rejected.
invalid-feedback Example : <form class="was-validated">
<div class="mb-3">
<label class="form-label">Username</label>
<input type="text" class="form-control" required>
<div class="valid-feedback">Looks good!</div>
<div class="invalid-feedback" >Enterusername.</div>
</div></form>
.form-control-* Input sizes (lg,sm)
Example : <input class="form-control form-control-lg">
.btn Basic button
.btn-*
Example : <button class="btn btn-primary">Submit</button>
is-valid Green border for correct input.
Example : <input class="form-control is-valid">
is-invalid Red border for incorrect input.
Example : <input class="form-control is-invalid">
.was-validated Used on the form tag to activate Bootstrap validation styles after submission.
(applied to <form>)
Example : <form class="was-validated">
<div class="mb-3">
<label class="form-label">Name</label>
<input type="text" class="form-control" required>
</div></form>
.input-group Used to add icons/text with input.
.input-group-text Example : <div class="input-group mb-3">
<span class="input-group-text">@</span>
<input type="text" class="form-control" placeholder="Username"> </div>
.row +.col inside forms Form Inline (side-by-side)
Example :<div class="row mb-3">
<div class="col">
<input class="form-control" placeholder="First Name">
</div> </div>
PAGE 23
Example 3:
<form>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email
address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-
describedby="emailHelp">
<div id="emailHelp" class="form-text">We'll never share your email with
anyone else.</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1">
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me
out</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
PAGE 24
Example 5:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Complete Bootstrap Form</title>
</head>
<body class="p-4">
PAGE 25
<div class="invalid-feedback">Username is required.</div>
</div>
</div>
PAGE 26
<!-- Checkbox -->
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" required>
<label class="form-check-label">I agree to the terms & conditions</label>
<div class="mb-3">
<label class="form-label">Small Input</label>
<input type="text" class="form-control form-control-sm">
</div>
</form>
</body>
</html>
PAGE 27