38 42 Bootstrap
38 42 Bootstrap
38 42 Bootstrap
(24CSE0102)
These breakpoints cover common device sizes and viewport dimensions. These
bootstrap breakpoints can be changed using Sass
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1400px );
Media queries
<!DOCTYPE html>
<html lang="en">
<head> <title>Bootstrap - Breakpoint</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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>
<style>
.custom-class {
display: none;
}
@media (min-width: 768px)
{ .custom-class {
display: block; } @media (min-width: 768px) { .custom-class { display: block; } } </style> </head>
Min-width
<body>
<h5>This block is visible on all devices</h5>
<div class="container-fluid mt-2 "> <div class="row">
<div class="col-md-6 bg-warning p-3"> md-6 warning
</div>
</div>
</div><br>
<h5>This block is not visible for sm breakpoint but visible for other breakpoints</h5>
<div class="container-fluid mt-2 custom-class">
<div class="row">
<div class="col-md-6 bg-warning p-3"> md-6 warning
</div>
</div>
</div>
</body>
</html>
Max-width
Bootstrap grid supports six responsive breakpoints. Breakpoints affect all sizes above
it (such as sm, md, lg, xl, xxl), allowing you to control container and column sizing
and behavior at each breakpoint.
Containers center and horizontally pad your content. Use .container for responsive
pixel width or .container-fluid for full width across all viewport and device sizes.
For various breakpoints the responsive container classes are used.
Rows are wrappers for columns. Each column contains horizontal padding. This
padding is then applied to rows with negative margins. In this manner, all the
content in the columns, is left-aligned.
Rows supports modification classes for uniform column sizing column sizing and
gutter classes for changing the spacing of your text.
Working of Bootstrap Grid
System
Columns are incredibly flexible. You can create various elements combination with
any number of columns using one of the 12 template columns available per row.
Column widths are set in percentages for fluid and relative sizing to parent element.
Gutters are responsive and customizable. They are available for all the viewports and
are of same size as margin and padding. You can modify gutters by using the .gx-
* (for horizontal gutters), .gy-* (for vertical gutters), .g-* (for all gutters) and .g-0
to remove gutters.
To create more semantic markup, you can use predefined grid's source Sass mixins.
Working of Bootstrap Grid
System
• Small (.col-sm-)
• Medium (.col-md-)
• Large (.col-lg-)
.d-inline example:
Example
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Display</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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 m-3 p-5">
<div class="d-inline m-2 p-4 text-bg-success">d-inline - success</div>
<div class="d-inline p-4 text-bg-warning">d-inline - warning</div>
</div>
</body>
</html>
Bootstrap Display
. .d-block example:
Example
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Display</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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">
<h4>Display - block</h4>
<span class="d-block p-4 text-bg-info">d-block used for info</span>
<span class="d-block p-4 text-bg-primary">d-block used for primary</span>
</div>
</body>
</html>
Margin and padding
• Use margin and padding utilities to modify the element's spacing and sizing.
It has a six-level spacing scale for spacing utilities based on 1rem default
$spacer variable.
• You can select certain viewports (e.g., .me-sm-3 for margin-right: 1rem —in
LTR— starting at the sm breakpoint), or values for the viewports (e.g., .me-3
for margin-right: 1rem in LTR).
Toggle visibility
• The utility classes that controls the visibility of the content on the webpage.
• The text on the webpage is visible due to the use of visibility class ".visible".
Example
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Visibility</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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-2">
<h4 class="display-5 text-success">
Visibility utility classes
</h4>
</div>
<div class="container mx-5 p-3">
<strong>The utility classes that controls the visibility of the content on the webpage.</strong>
<p class="visible text-bg-primary">
The text on the webpage is visible due to the use of visibility class ".visible".
</p>
<p class="invisible">
The text on the webpage is not visible due to the use of visibility class ".invisible".
</p>
<p class="text-bg-warning">This is the text that is without a visibility class usage.</p>
Bootstrap Components
Bootstrap Components
The alert messages are often the stand out messages shown to the user, where
some user action is required, such as warning, error, information or
confirmation messages.
By extending the .alert base class with the contextual classes (such as .alert-
success, .alert-warning, .alert-info, etc.), you can quickly and simply build
attractive alert messages for any number of reasons using Bootstrap. To cancel
any alert, you may also include an optional close button.
Simple Alerts
There is a total of 8 different alert types offered by Bootstrap. The most typical
alerts, such as success, error or danger, warning and info alerts, etc.
Alert - Example
Alert - Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap - Alerts</title>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
</div>
</div>
</body>
</html>
Bootstrap Buttons
Base button
Add .btn class that implements basic styles such as padding and content
alignment. The .btn class provides a transparent border, a background color,
and no explicit focus and hover styles.
Example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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>
<title>Bootstrap - Buttons</title>
</head>
<body>
<button type="button" class="btn btn-primary">Base Button </button>
</body>
</html>
Variants
Bootstrap includes different styles of buttons, each serving its own
semantic purpose, with some extras thrown in for further control. To
achieve the button styles, Bootstrap provides following classes:
• .btn
• .btn-default
• .btn-primary
• .btn-success
• .btn-info
• .btn-warning
• .btn-danger
• .btn-link
Example
<DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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>
<title>Bootstrap - Buttons</title>
</head>
<body>
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-dark">Dark</button>
<button type="button" class="btn btn-link">Link</button>
</body>
Bootstrap Dropdowns
The .btn class can be converted into a dropdown menu/toggle with some markup
changes.
Example
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap - Dropdowns</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-
expanded="false">
Dropdown Button
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Create Account</a></li>
<li><a class="dropdown-item" href="#">Sign in</a></li>
<li><a class="dropdown-item" href="#">Sign out</a></li>
</ul>
Bootstrap Modals
Modals are a type of component that are used to display content or messages in a
customizable dialog box that overlays the current page.
• Modals can be used for a variety of purposes such as displaying images, videos, forms,
and notifications.
• Modals are useful for creating a user-friendly and interactive interface because they allow
users to interact with content without leaving the current page.
• They can also be easily customized using Bootstrap's built-in classes and JavaScript
plugins.
• Modal gets closed automatically when the modal backdrop is clicked.
• Only one modal window at a time is supported by Bootstrap.
• It is advised to avoid nesting a .modal within another element. Rather place your modal
in a top-level position to avoid any interference from other elements.
• Using modals on mobile devices comes with certain limitations because of position:
fixed.
• Animation effect of the modal component depends upon the prefers-reduced-
motion media query.
• The autofocus HTML attribute is ineffective in Bootstrap modals because of the way
HTML5 defines its semantics. A comparable result can be attained by employing specially
crafted JavaScript code.
Bootstrap Modals
Modal components:
• Modal header - Contains the title and a close button.
• Modal body - Contains the content of the modal.
• Modal footer - Contains buttons or other actions that may be available to the
user.
• Modal backdrop - A semi-transparent overlay that covers the background
when the modal is active.
• Modal content - The container that houses the header, body, and footer
components.
• Modal dialog - The outermost container that defines the size of the modal
and the location of the content within it.
Example
<html>
<head>
<title>Bootstrap - Modal</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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 style="text-align: center;">
<div class="container mt-3" style="width: 700px;">
<h4>Static Modal</h4>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-
target="#exampleModal">Launch modal</button>
<!-- Modal -->
<div class="modal" id="exampleModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-
Example (Contd..)
<button type="button"
class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-
body"><strong><h4>Example of a Static Modal</h4></strong></div>
<div class="modal-footer">
<button type="button"
class="btn btn-danger" data-bs-dismiss="modal">Close</button>
<button type="button"
class="btn btn-success">Save</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>