Bootstrap PDF
Bootstrap PDF
Bootstrap is a popular front-end framework that provides a set of tools and templates for
creating responsive and mobile-first websites and web applications. It includes HTML and
CSS-based design templates for typography, forms, buttons, navigation, and other interface
components, as well as optional JavaScript extensions for interactive elements.
Example:
Let's say you want to create a simple webpage with a navigation bar, a heading, some text, and a
button. Using Bootstrap, you can achieve this quickly with minimal code.
1. Setting up Bootstrap:
o Include Bootstrap's CSS and JavaScript files in your HTML document. You can
do this by linking to Bootstrap's CDN (Content Delivery Network) or by
downloading Bootstrap and linking to the files locally.
Container
Definition and Usage:
The container class in Bootstrap is used to wrap the content of your website within a fixed-
width container. It ensures that the content inside it is centered and aligned properly on different
screen sizes, providing a consistent layout.
Types of Containers:
1. Container:
o The basic .container class provides a responsive fixed-width container.
o It adjusts its width depending on the viewport size (breakpoints), ensuring the
content inside is not excessively wide on large screens and remains properly
aligned on smaller screens.
HTML Code:
<div class="container">
</div>
2 Fluid Container:
HTML Code:
<div class="container-fluid">
</div>
Key Features:
Layout Structure: Use containers to structure your page content into distinct sections.
Responsive Layouts: Containers ensure that your content is responsive and adapts well
to various screen sizes.
Fixed vs. Fluid: Choose between .container for a fixed-width layout or .container-
fluid for a full-width layout based on your design needs.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
</div>
</div>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
Explanation:
The .container class is used for a fixed-width container that centers its content and
adjusts its width responsively.
The .container-fluid class creates a full-width container that spans the entire viewport
width, suitable for fluid layouts.
Each container wraps its content, providing padding and ensuring proper alignment
across different screen sizes.
The table below illustrates how each container’s max-width compares to the
original .container and .container-fluid across each breakpoint.
See them in action and compare them in our Grid example.
Responsive containers
Responsive containers allow you to specify a class that is 100% wide until the specified
breakpoint is reached, after which we apply max-widths for each of the higher breakpoints. For
example, .container-sm is 100% wide to start until the sm breakpoint is reached, where it will
scale up with md, lg, xl, and xxl.
HTML code:
HTML Code:
<button type = " button " class = " btn btn-primary " > Default Button </ button >
HTML Code
</div>
</label>
</label>
</label>
</div>
Badges in Bootstrap
In Bootstrap, badges are small components typically used to indicate numeric values (like counts
or notifications) in an aesthetically pleasing way. Here's a clear breakdown of how to use badges
along with an example:
Basic Badge
A basic badge is created using the <span> element with the class .badge. You can customize the
appearance of badges using additional classes.
Example:
<span class="badge badge-primary">New</span>
In this example:
- `type="button"` specifies that this button does not submit a form, it simply performs an
action when clicked (standard button behavior).
- `btn-primary`: This is a Bootstrap class that gives the button a primary color, typically a
shade of blue, indicating that it represents the main action or primary action in a set of
buttons.
- Inside the `<button>` element, there is text "Profile" followed by a `<span>` element.
- The number `9` inside the `<span>` is typically used to indicate a count or some form of
status. In this case, it might represent unread messages or notifications.
- It visually hides the content within it from users but makes it available to screen readers.
- It's often used to provide additional context or information for accessibility without
cluttering the visual interface.
- In this case, it contains the text "unread messages", which provides a description for the
badge count "9" to users who rely on screen readers.
In summary, this code snippet creates a styled Bootstrap button labeled "Profile" with a
primary blue color. It includes a badge indicating the number "9" (potentially representing
unread messages or notifications) and provides accessibility support with hidden text for
screen readers.
Pill badges are a type of badge in Bootstrap that have more rounded corners, giving them a pill-
like shape. They are created by adding the .rounded-pill class to the .badge class.
Positioning
Pill badges can be positioned in the corner of a link or button using positioning utility classes.
Badges in Buttons
You can place badges inside buttons to indicate additional information, such as counts or
statuses.
Example:
</button>
Utility Classes
Bootstrap also provides utility classes to adjust badges easily, such as .badge-lg for larger
badges and .badge-sm for smaller badges.
Example:
Conclusion
Bootstrap badges are versatile components that can be used to highlight and display various
types of information in a visually appealing manner. By utilizing different classes and styles, you
can integrate badges seamlessly into your web projects to enhance user experience and provide
clear notifications or indicators.
Alerts in Bootstrap
Provide contextual feedback messages for typical user actions with the handful of available and
flexible alert messages.
Success Alerts
<div class="alert alert-success" role="alert">
</div>
Info Alerts
<div class="alert alert-info" role="alert">
</div>
Danger Alerts
<div class="alert alert-danger" role="alert">
</div>
In addition to these main types, Bootstrap also provides the following alert variations:
You can apply these classes to the .alert base class to create the desired alert style.
Alert Structure
The basic structure of a Bootstrap alert is:
</div>
i. The outer <div> element has the .alert class to apply the base alert styles.
ii. The alert-[type] class (e.g. alert-success) is used to apply the specific alert color.
iii. The role="alert" attribute is used for accessibility, indicating that this is an alert message.
iv. The <strong> element is used to make the alert heading bold.
v. The alert message text follows the heading.
Dismissible Alerts
You can make an alert dismissible by adding the .alert-dismissible class to the outer <div> and
including a close button:
</div>
The .alert-dismissible class adds the styles for the close button.
The fade show classes add a fade-in animation when the alert is shown.
The data-bs-dismiss="alert" attribute on the button tells Bootstrap to dismiss the alert
when clicked.
The aria-label="Close" attribute is for accessibility, describing the purpose of the button.
</div>
The .alert-link class will style the link to match the alert's color.
</svg>
<div>
</div>
</div>
Basic Example To create a basic button group, wrap a series of .btn elements in a .btn-
group container:
</div>
The role="group" and aria-label attributes are important for accessibility, as they inform assistive
technologies that these buttons are part of a group.
Mixed Styles
You can use different button styles within the same button group:
</div>
Outlined Styles
You can also use outlined button styles within a button group:
</div>
</label>
</div>
</label>
</label>
</label>
</div>
Sizing
Instead of applying button sizing classes to every button in a group, you can add .btn-group-
lg, .btn-group-sm, or .btn-group-xs to the .btn-group container to size all buttons in the group:
My Example Coding
</div>
Vertical Variation
To stack the buttons vertically instead of horizontally, use the .btn-group-vertical class:
</div>
Button Toolbar
Combine sets of button groups into button toolbars for more complex components. Use utility
classes as needed to space out groups, buttons, and more.
For more complex layouts, you can combine multiple button groups into a button toolbar using
the .btn-toolbar class.
</div>
</div>
</div>
</div>
The button group component in Bootstrap provides a flexible way to group related buttons
together and create complex button-based layouts. By using the appropriate classes and
attributes, you can create a variety of button group styles and behaviors to suit your needs.
Nav-bar in Bootstrap
Documentation and examples for Bootstrap’s powerful, responsive navigation header, the
navbar. Includes support for branding, navigation, and more, including support for our collapse
plugin.
Navbar using Anchor Tag
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-nav">
</div>
</div>
</nav>
Output Hare
Explanation Hare
<div class="collapse navbar-collapse"
id="navbarNavAltMarkup">
<div class="navbar-nav">
</ul>
Cards Component in Bootstrap
Bootstrap’s cards provide a flexible and extensible content container with multiple variants and
options.
<div class="card-body">
<p class="card-text">Some quick example text to build on the card title and make up the bulk
of the card's content.</p>
</div>
</div>
Titles, text, and links:
Card titles are used by adding .card-title to a <h*> tag. In the same way, links are added and
placed next to each other by adding .card-link to an <a> tag.
Subtitles are used by adding a .card-subtitle to a <h*> tag. If the .card-title and the .card-
subtitle items are placed in a .card-body item, the card title and subtitle are aligned nicely.
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk
of the card's content.</p>
</div>
</div>
Code:
<div class="container">
<h2>Grid System Practise</h2>
<div class="row">
<div class="col-4 bg-danger">ONE-1</div>
<div class="col-4 bg-primary">TWO-2</div>
<div class="col-4 bg-success">THREE-3</div>
</div>
</div>
Grid options for Responsive
Bootstrap's grid system has six default breakpoint tiers that adapt the layout across different
screen sizes: