UNIT 5 Bootstrap
UNIT 5 Bootstrap
Consistency:
It ensures design consistency across all pages and projects.
Ease of Use:
Even beginners can quickly build professional-looking websites with minimal effort.
Bootstrap Layouts:
Container
The container is the outermost element in the layout system. It provides a way to center content
and give padding.
Types of Containers:
.container: Fixed-width container that adjusts based on screen size.
.container-fluid: Full-width container spanning the entire width of the viewport.
.container-{breakpoint}: Responsive container that changes width based on the specified
breakpoint (sm, md, lg, etc.).
<div class="container">
Fixed width based on screen size.
</div>
<div class="container-fluid">
Full width on all screen sizes.
</div>
<div class="container-lg">
Fixed width only on large screens and above.
</div>
Row:
A row is used to wrap columns and ensure proper alignment and spacing. Rows create a
horizontal group of columns, maintaining spacing using gutters (default spacing between
columns).
<div class="container">
<div class="row">
<div class="col">Column 1</div>
<div class="col">Column 2</div>
</div>
</div>
Columns:
Columns are the building blocks of Bootstrap's grid system. The grid divides into 12 equal
parts, and you can specify how many parts each column should occupy.
Key Features:
Auto-layout columns: Automatically divide available space equally.
Defined-width columns: Use .col-{breakpoint}-{number} classes to set column widths.
Nested columns: Columns can contain additional rows and columns.
Responsive Classes
Bootstrap provides classes for different screen sizes (breakpoints). You can use these to define
column widths for specific screen sizes:
Breakpoints:
col-sm (Small: ≥576px)
col-md (Medium: ≥768px)
col-lg (Large: ≥992px)
col-xl (Extra large: ≥1200px)
col-xxl (Extra-extra large: ≥1400px)
<div class="row">
<div class="col-sm-6 col-lg-4">Responsive Column</div>
<div class="col-sm-6 col-lg-8">Responsive Column</div>
</div>
Offset Columns:
Offsets are used to add empty space before a column. Use .offset-{breakpoint}-{number} to
shift columns to the right.
<div class="row">
<div class="col-4 offset-2">Offset by 2 columns</div>
<div class="col-4">Column</div>
</div>
Reordering Columns:
Reordering allows you to change the order of columns using .order-{breakpoint}-{number}
classes. Numbers range from 1 (highest priority) to 12 (lowest priority).
<div class="row">
<div class="col order-3">Third</div>
<div class="col order-1">First</div>
<div class="col order-2">Second</div>
</div>
For reverse order, use .order-last or .order-first.
<h1>Big Title</h1>
<h2>Smaller Title</h2>
Paragraphs:
For regular text, use <p>. It adds proper spacing.
<p>This is a paragraph with good spacing.</p>
<strong>Bold text</strong>
<em>Italic text</em>
Lists:
Use <ul> for bullet points and <ol> for numbered lists.
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
2. Tables
Bootstrap makes tables look cleaner and adds features like borders and stripes.
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>25</td>
</tr>
</tbody>
</table>
Add borders:
<table class="table table-bordered"></table>
3. Images
Bootstrap can make images responsive (fit the screen size) and styled.
Responsive Image:
<img src="image.jpg" class="img-fluid" alt="Description">
The img-fluid class makes the image adjust automatically to fit the screen.
Rounded Image:
<img src="image.jpg" class="rounded" alt="Rounded image">
Circle Image:
<img src="image.jpg" class="rounded-circle" alt="Circular image">
Basic Form:
<form>
<div class="mb-3">
<label for="exampleInputEmail" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail" placeholder="Enter
email">
</div>
<div class="mb-3">
<label for="exampleInputPassword" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleInputPassword"
placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Bootstrap Components:
1. Navbar
The Navbar is a responsive, collapsible header used for navigation menus.
Can include links, brand logos, dropdowns, and search bars.
Customizable with different colors (bg-light, bg-dark) and positions (e.g., fixed-top).
3. Dropdowns
Dropdowns are toggled menus that expand to show additional links or actions.
Triggered by buttons or links with .dropdown-toggle.
Positioning and alignment can be adjusted (dropup, dropright).
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-
toggle="dropdown">
Dropdown
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
</ul>
</div>
4. Buttons
Buttons are styled clickable elements for various actions.
Styles: .btn-primary, .btn-secondary, .btn-success, etc.
Sizes: .btn-sm (small), .btn-lg (large).
Variants like outline buttons: .btn-outline-primary.
5. Button Groups
Button Groups allow grouping multiple buttons together for compact layouts.
Use .btn-group to combine buttons horizontally or .btn-group-vertical for vertical alignment.
<div class="btn-group">
<button class="btn btn-primary">Left</button>
<button class="btn btn-primary">Middle</button>
<button class="btn btn-primary">Right</button>
</div>
6. Breadcrumb
Breadcrumbs show the user’s navigation path (e.g., Home > Library > Books).
Use .breadcrumb for the container and .breadcrumb-item for individual links.
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active">Library</li>
</ol>
</nav>
7. Pagination
Pagination splits content into multiple pages.
Use .pagination for the container and .page-item for individual links.
Add .disabled or .active to style specific items.
<nav>
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
</nav>
8. Labels/Badges
Badges are small indicators to highlight notifications, counts, or statuses.
Example: .badge bg-primary, .badge bg-danger.
9. Alerts
Alerts are used for messages or notifications.
Examples: .alert-success (green for success), .alert-danger (red for error).
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 50%;">50%</div>
</div>
11. Accordion
Accordion is a collapsible list used for FAQs or toggleable sections.
Use .accordion as the container, .accordion-item for each item.
12. Card
Cards are containers for content like text, images, and actions.
Can include a header, footer, and body for structured content.
13. Modal
Modals are pop-up dialogs used for forms, alerts, or other interactions.
Use .modal for the container and include .modal-dialog for the structure.
Bootstrap Utilities:
1. Colors
Control text and background colors:
Text: .text-primary, .text-danger.
Background: .bg-primary, .bg-success.
2. Background
Apply solid or gradient backgrounds:
Colors: .bg-light, .bg-dark.
Gradients: .bg-gradient.
3. Borders
Style element borders:
Add borders: .border, .border-top, .border-0 (remove border).
Rounding: .rounded, .rounded-circle.
4. Display
Control element visibility:
Hide/show: .d-none, .d-block, .d-flex.
Responsive: .d-md-none (hide on medium screens).
5. Overflow
Control overflow behavior:
.overflow-auto (scrollable), .overflow-hidden (cut-off content).
6. Position
Position elements:
Static: .position-static (default).
Fixed: .position-fixed (fixed on the screen).
Absolute: .position-absolute (relative to parent).
7. Spacing
Adjust margins and padding:
Margins: .m-3 (margin), .mt-3 (top margin).
Padding: .p-3 (padding), .pt-3 (top padding).
8. Text
Control text styling:
Alignment: .text-start, .text-center, .text-end.
Transformation: .text-uppercase, .text-lowercase.
9. Vertical Align
Align inline or table elements vertically:
.align-baseline, .align-top, .align-middle, .align-bottom.