WE LAB 7 - 2k22
WE LAB 7 - 2k22
Laboratory # 07
10/04/2024
UET TAXILA
Engr. Sidra Shafi
Bootstrap 5 is the newest version of Bootstrap, which is the most popular HTML, CSS, and
JavaScript free front-end framework for creating faster and easier responsive, mobile-first
websites.
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 Versions
Bootstrap 5 (released 2021) is the newest version of Bootstrap (released 2013); with new
components, faster stylesheet and more responsiveness.
Bootstrap 5 supports the latest, stable releases of all major browsers and platforms. However,
Internet Explorer 11 and down is not supported.
The main differences between Bootstrap 5 and Bootstrap 3 & 4, is that Bootstrap 5 has switched
to vanilla JavaScript instead of jQuery.
There are two ways to start using Bootstrap 5 on your own web site.
You can:
The first way is to use a CDN or Content delivery network. Using bootstrap CDN means that we
will not download and store the bootstrap files in our server or local machine. We will just include
the bootstrap CSS and JavaScript links to our page.
MaxCDN:
Downloading Bootstrap 5:
If you want to download and host Bootstrap 5 yourself, go to https://getbootstrap.com/, and follow
the instructions there.
Install Bootstrap’s source Sass and JavaScript files via npm, RubyGems, Composer, or Meteor.
Package managed installs don’t include documentation or our full build scripts.
Terminal:
npm install [email protected]
Example: Images_local_st.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 5 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></scri
pt>
</head>
<body>
<div class="container-fluid p-5 bg-primary text-white text-center">
<h1>Bootstrap 5 Page</h1>
<p>Resize this responsive page to see the effect!</p>
</div>
<div class="container mt-5">
<div class="row">
<div class="col-sm-4">
<h3>Column 1</h3>
<p class="text-end">Video provides a powerful way to help you prove your point. When you
click Online Video, you can paste in the embed code for the video you want to add. You can also
type a keyword to search online for the video that best fits your document....</p>
<p class="text-start">To make your document look professionally produced, Word provides
header, footer, cover page, and text box designs that complement each other. For example, you
can add a matching cover page, header, and sidebar. Click Insert and then choose the elements
you want from the different galleries....</p>
</div>
<div class="col-sm-4">
<h3>Column 2</h3>
<p class="text-wrap">Video provides a powerful way to help you prove your point. When
you click Online Video, you can paste in the embed code for the video you want to add. You can
also type a keyword to search online for the video that best fits your document....</p>
<p>To make your document look professionally produced, Word provides header, footer,
cover page, and text box designs that complement each other. For example, you can add a
matching cover page, header, and sidebar. Click Insert and then choose the elements you want
from the different galleries....</p>
</div>
<div class="col-sm-4">
<h3>Column 3</h3>
<p>Video provides a powerful way to help you prove your point. When you click Online
Video, you can paste in the embed code for the video you want to add. You can also type a
keyword to search online for the video that best fits your document....</p>
<p>To make your document look professionally produced, Word provides header, footer,
cover page, and text box designs that complement each other. For example, you can add a
matching cover page, header, and sidebar. Click Insert and then choose the elements you want
from the different galleries....</p>
</div>
</div>
</div>
</body>
</html>
Output:
Bootstrap Spacing:
Assign responsive-friendly margin or padding values to an element or a subset of its sides with
shorthand classes. Includes support for individual properties, all properties, and vertical and
horizontal properties. Classes are built from a default Sass map ranging from .25rem to 3rem.
Notation:
Spacing utilities that apply to all breakpoints, from xs to xxl, have no breakpoint abbreviation in
them. This is because those classes are applied from min-width: 0 and up, and thus are not bound
by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation.
The classes are named using the format {property}{sides}-{size} for xs and {property}{sides}-
{breakpoint}-{size} for sm, md, lg, xl, and xxl.
• e - (end) for classes that set margin-right or padding-right in LTR, margin-left or padding-left in
RTL
• blank - for classes that set a margin or padding on all 4 sides of the element
• 1 - (by default) for classes that set the margin or padding to $spacer * .25
• 2 - (by default) for classes that set the margin or padding to $spacer * .5
• 3 - (by default) for classes that set the margin or padding to $spacer
• 4 - (by default) for classes that set the margin or padding to $spacer * 1.5
• 5 - (by default) for classes that set the margin or padding to $spacer * 3
(You can add more sizes by adding entries to the $spacers Sass map variable.)
Horizontal centering:
Additionally, Bootstrap also includes an .mx-auto class for horizontally centering fixed-width
block level content—that is, content that has display: block and a width set—by setting the
If you do not want to use all 12 columns individually, you can group the columns together to
create wider columns:
If you do not want to use all 12 columns individually, you can group the columns together to create
wider columns:
Bootstrap's grid system is responsive, and the columns will re-arrange depending on the screen
size: On a big screen, it might look better with the content organized in three columns, but on a
small screen it would be better if the content items were stacked on top of each other.
Make sure that the sum adds up to 12 or fewer (it is not required that you use all 12 available
columns).
Grid Classes:
The classes above can be combined to create more dynamic and flexible layouts.
Note: Each class scales up, so if you wish to set the same widths for sm and md, you only
need to specify sm.
Example: Three elements with .col-sm will each automatically be 33.33% wide from the small
breakpoint and up.
<!-- Control the column width, and how they should appear on different
devices -->
<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>
First example: create a row (<div class="row">). Then, add the desired number of columns (tags
with appropriate .col-*-* classes). The first star (*) represents the responsiveness: sm, md, lg, xl
or xxl, while the second star represents a number, which should add up to 12 for each row.
Second example: instead of adding a number to each col, let bootstrap handle the layout, to create
equal width columns: two "col" elements = 50% width to each col, while three cols = 33.33%
width to each col. Four cols = 25% width, etc. You can also use .col-sm|md|lg|xl|xxl to make the
columns responsive.
Example: Grid_classes_bootstrap5_medium
Examples:
Below we have collected some examples of basic Bootstrap 5 grid layouts.
Lab Exercise: 1
<!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 href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container-fluid mt-3">
<h1>Three equal width columns</h1>
<p>Note: Try to add a new div with class="col" inside the row class - this will create four equal-width
columns.</p>
<div class="row">
<div class="col-sm-4 p-3 bg-primary text-white">.col</div>
<div class="col-sm-4 p-3 bg-dark text-white">.col</div>
<div class="col-sm-4 p-3 bg-primary text-white">.col</div>
</div>
</div>
</body>
</html>
Create two un-equal width columns (4+8) that are shown like this division on medium, large
and extra-large devices, but stack on small and extra small devices.
Note: You can turn any fixed-width layout into a full-width layout by changing the .container
class to .container-fluid:
Output:
Lab Exercise: 3
What will be the distribution of classes for a 33.3% / 66.6% split and for a 50% / 50% split?
Medium Grid Example:
Note: For medium devices we will use the .col-md-* classes:
Now Bootstrap is going to say "at the small size, look at classes with -sm- in them and use those.
At the medium size, look at classes with -md- in them and use those".
The following example will result in a 25%/75% split on small devices and a 50%/50% split on
medium (and large and xlarge) devices. On extra small devices, it will automatically stack (100%):
Example:
<!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
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js
"></script>
</head>
<body>
<div class="container-fluid">
<h1>Medium Grid</h1>
<p>The following example will result in a 25%/75% split on small devices and a
50%/50% split on medium (and large and xlarge) devices. On extra small devices,
it will automatically stack (100%).</p>
<p>Resize the browser window to see the effect.</p>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-6 bg-success">
Video provides a powerful way to help you prove your point. When you
click Online Video, you can paste in the embed code for the video you want to
add. You can also type a keyword to search online for the video that best fits
your document.
</div>
<div class="col-sm-9 col-md-6 bg-warning">
Video provides a powerful way to help you prove your point. When you
click Online Video, you can paste in the embed code for the video you want to
add. You can also type a keyword to search online for the video that best fits
your document.
</div>
</div>
</div>
</div>
</body>
</html>
Output:
On small Devices:
Lab Exercise: 4 :- Use only the medium class in above example and check the outputs.
Large Grid Example:
Note: For large devices we will use the .col-lg-* classes:
Now Bootstrap is going to say "at the small size, look at classes with -sm- in them and use those.
At the medium size, look at classes with -md- in them and use those. At the large size, look at
classes with the word -lg- in them and use those".
The following example will result in a 25%/75% split on small devices, a 50%/50% split on
medium devices, and a 33%/66% split on large, xlarge and xxlarge devices. On extra small devices,
it will automatically stack (100%):
Example:
<!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 href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h1>Large Grid</h1>
<p>The following example will result in a 25%/75% split on small devices and a 50%/50% split
on medium and 33%/66% split on large, xlarge and xxlarge devices. On extra small devices, it will
automatically stack (100%).</p>
<p>Resize the browser window to see the effect.</p>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4 bg-success">
Video provides a powerful way to help you prove your point. When you click Online Video,
you can paste in the embed code for the video you want to add. You can also type a keyword to
search online for the video that best fits your document.
</div>
<div class="col-sm-9 col-md-6 col-lg-8 bg-warning">
Video provides a powerful way to help you prove your point. When you click Online Video,
you can paste in the embed code for the video you want to add. You can also type a keyword to
search online for the video that best fits your document.
</div>
</div>
</div>
</div>
</body>
</html>
Output:
With Bootstrap, a navigation bar can extend or collapse, depending on the screen size.
A standard navigation bar is created with the .navbar class, followed by a responsive collapsing
class: .navbar-expand-xl|lg|md|sm (stacks the navbar vertically on extra large, large, medium or
small screens).
To add links inside the navbar, use a <ul> element with class="navbar-nav". Then
add <li> elements with a .nav-item class followed by an <a> element with a .nav-link class:
Code:
<!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 href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
</body>
</html>
Output:
Centered Navbar:
Add the .justify-content-center class to center the navigation bar.
<!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
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-light justify-content-center">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 3</a>
</li>
</ul>
</nav>
Output:
Colored Navbar:
Use any of the .bg-color classes to change the background color of the navbar (.bg-primary, .bg-
success, .bg-info, .bg-warning, .bg-danger, .bg-secondary, .bg-dark and .bg-light)
Tip: Add a white text color to all links in the navbar with the .navbar-dark class, or use
the .navbar-light class to add a black text color.
Example: centerednavbar.html
<!-- Grey with black text -->
<nav class="navbar navbar-expand-sm bg-light navbar-light justify-content-center">
<!-- Blue background with white text -->
<nav class="navbar navbar-expand-sm bg-primary navbar-dark justify-content-center">
Fixed Navigation-Bar:
The navigation bar can also be fixed at the top or at the bottom of the page.
A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the page scroll.
The .fixed-top class makes the navigation bar fixed at the top:
Example:
Use the .fixed-bottom class to make the navbar stay at the bottom of the page:
Very often, especially on small screens, you want to hide the navigation links and replace them
with a button that should reveal them when clicked on.
Example:
<!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 href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<!-- Brand -->
<a class="navbar-brand" href="#">Logo</a>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-
target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>
</nav>
</body>
</html>
Note: You can also remove the .navbar-expand-sm class to ALWAYS hide navbar links and
display the toggler button.
Output:
Example:
<!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 href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<!-- Brand -->
<a class="navbar-brand" href="#">Logo</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-
target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<!-- Links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<!-- Dropdown -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-
toggle="dropdown">Dropdown</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
<li><a class="dropdown-item" href="#">A third link</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid mt-3">
<h3>Navbar With Dropdown</h3>
<p>This example adds a dropdown menu in the navbar.</p>
</div>
</body>
</html>
Output:
Example explanation:
The .dropdown class indicates a dropdown menu.
To open the dropdown menu, use a button or a link with a class of .dropdown-toggle and the data-
toggle="dropdown" attribute.
Add the .dropdown-menu class to a <ul> element to actually build the dropdown menu.
Since we do not have any page to link it to, and we do not want to get a "404" message, we put #
as the link. In real life it should of course been a real URL to the "Search" page.
Bootstrap 5 Buttons:
Bootstrap 5 provides different styles of buttons:
Button Sizes:
Use the .btn-lg class for large buttons or .btn-sm class for small buttons:
Active/Disabled Buttons:
A button can be set to an active (appear pressed) or a disabled (unclickable) state.
The class .active makes a button appear pressed, and the disabled attribute makes a button
unclickable. Note that <a> elements do not support the disabled attribute and must therefore use
the .disabled class to make it visually appear disabled.
Spinner Buttons:
You can also add "spinners" to a button.
Disabled Buttons:
Bootstrap Collapse:
Collapsibles are useful when you want to hide and show large amount of content:
Code:
<!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 href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container mt-3">
<h2>Simple Collapsible</h2>
<p>Click on the button to toggle between showing and hiding content.</p>
<button type="button" class="btn btn-primary" data-bs-toggle="collapse" data-bs-
target="#demo">Simple collapsible</button>
<div id="demo" class="collapse">
Video provides a powerful way to help you prove your point. When you click Online Video, you can
paste in the embed code for the video you want to add. You can also type a keyword to search online for
the video that best fits your document.
</div>
</div>
</body> </html>
Output:
Example Explained:
The .collapse class indicates a collapsible element (a <div> in our example); this is the content
that will be shown or hidden with a click of a button.
To control (show/hide) the collapsible content, add the data-bs-toggle="collapse" attribute to an
<a> or a <button> element. Then add the data-bs-target="#id" attribute to connect the button with
the collapsible content (<div id="demo">).
Note: For <a> elements, you can use the href attribute instead of the data-bs-target attribute:
By default, the collapsible content is hidden. However, you can add the .show class to show the
content by default.
Image:
Images come in all sizes. So do screens. Responsive images automatically adjust to fit the size of
the screen.
Create responsive images by adding an .img-fluid class to the <img> tag. The image will then
scale nicely to the parent element.
The .img-fluid class applies max-width: 100%; and height: auto; to the image.
Example:
Centered Image:
Center an image by adding the utility classes .mx-auto (margin:auto) and .d-block (display:block)
to the image:
Aligning Images:
Float an image to the left with the .float-start class or to the right with .float-end:
Example:
Thumbnail:
Example:
Lab Task
Design a web page as shown below using Bootstrap. Marks: 10
3. Style the "About us" section and the <footer> section of the page to display similar to
the screenshots
4. Read about offsetting columns, position and opacity in the bootstrap documentation link
is https://getbootstrap.com/docs/5.2/utilities/opacity/
IMPORTANT:
• Don't change the order of the 3 main cookie html tags, the <h3>, followed by
the <p>, and then the <img> tags. Remember, we want to keep semantic
order.
• You can add <div>'s and bootstrap classes as needed, you can wrap the tags
in div's as needed, as long as you don't change the order.
*****************************************