Python
Python
Advantages of Bootstrap:
Easy to use: Anybody with just basic knowledge of HTML and CSS can start using
Bootstrap
Responsive features: Bootstrap's responsive CSS adjusts to phones, tablets, and
desktops
Mobile-first approach: In Bootstrap, mobile-first styles are part of the core framework
Browser compatibility: Bootstrap 4 is compatible with all modern browsers (Chrome,
Firefox, Internet Explorer 10+, Edge, Safari, and Opera)
Create First Web Page with Bootstrap 4
2. Bootstrap 4 is mobile-first
Bootstrap 4 is designed to be responsive to mobile devices. Mobile-first styles are part of the
core framework.
To ensure proper rendering and touch zooming, add the following <meta> tag inside
the <head> element:
<meta name="viewport" content="width=device-width, initial-scale=1">
The width=device-width part sets the width of the page to follow the screen-width of the device
(which will vary depending on the device).
The initial-scale=1 part sets the initial zoom level when the page is first loaded by the browser.
3. Containers
Bootstrap 4 also requires a containing element to wrap site contents.
There are two container classes to choose from:
1. The .container class provides a responsive fixed width container
2. The .container-fluid class provides a full width container, spanning the entire width of
the viewport
<html lang="en">
<head>
<title>Bootstrap 4 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="D:\WEB-1\Practical\bootstrap-4.0.0-dist\css\bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body>
</html>
2.2 Grid Structure
Bootstrap's grid system is built with flexbox (easily format HTML) and allows up to 12 columns
across the page.
If you do not want to use all 12 columns individually, you can group the columns together to
create wider columns:
span span span span span span span span span span span span
1 1 1 1 1 1 1 1 1 1 1 1
span 4 span 8
span 6 span 6
span 12
Grid Classes
The Bootstrap 4 grid system has five classes:
.col- (extra small devices - screen width less than 576px)
.col-sm- (small devices - screen width equal to or greater than 576px)
.col-md- (medium devices - screen width equal to or greater than 768px)
.col-lg- (large devices - screen width equal to or greater than 992px)
.col-xl- (xlarge devices - screen width equal to or greater than 1200px)
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.
Basic Structure of a Bootstrap 4 Grid
The following is a basic structure of a Bootstrap 4 grid:
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="D:\WEB-1\Practical\bootstrap-4.0.0-dist\css\bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<h1>Responsive Columns</h1>
<p>Resize the browser window to see the effect.</p>
<p>The columns will automatically stack on top of each other when the screen is less than
576px wide.</p>
<div class="row">
<div class="col-sm-3" style="background-color:lavender;">.col-sm-3</div>
<div class="col-sm-3" style="background-color:lavenderblush;">.col-sm-3</div>
<div class="col-sm-3" style="background-color:lavender;">.col-sm-3</div>
<div class="col-sm-3" style="background-color:lavenderblush;">.col-sm-3</div>
</div>
</div>
</body>
</html>
2.3 Table, Colours, Alerts, Form Controls
Table
<p>The .table class adds basic styling (light padding and horizontal dividers) to a table:</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>Shalini</td>
<td>Mali</td>
<td>sm@example.com</td>
</tr>
<tr>
<td>Hiral</td>
<td>Patel</td>
<td>hp@example.com</td>
</tr>
<tr>
<td>Swaara</td>
<td>Desai</td>
<td>sd@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Classes use in table
table-striped, .table-bordered, .table-hover, .table-dark, .table-hover, .table-borderless, .table-
primary, .table-success, .table-danger, .table-info, .table-warning, .table-active, .table-
secondary, .table-light, .table-dark, .thead-dark, .thead-light, table-sm, .table-responsive,
.table-responsive-sm, .table-responsive-md, .table-responsive-lg, .table-responsive-xl,
<table class="table">
</table>
Colours
Bootstrap 4 has some contextual classes that can be used to provide "meaning through colors".
The classes for text colors are: .text-muted, .text-primary, .text-success, .text-info, .text-
warning, .text-danger, .text-secondary, .text-white, .text-dark, .text-body (default body
color/often black) , .text-light, text-black-50, text-white-50 bg-dark
Ex: <p class="text-muted"> This text is muted. </p>
Contextual text classes can also be used on links, which will add a darker hover color:
Ex: <a href="#" class="text-muted">Muted link.</a>
Background Colors
The classes for background colors are: .bg-primary, .bg-success, .bg-info, .bg-warning, .bg-
danger, .bg-secondary, .bg-dark and .bg-light.
Ex: <p class="bg-primary text-white">This text is important.</p>
Bootstrap 4 Alerts
Bootstrap 4 provides an easy way to create predefined alert messages:
Alerts are created with the .alert class, followed by one of the contextual classes .alert-
success, .alert-info, .alert-warning, .alert-danger, .alert-primary, .alert-secondary, .alert-
light or .alert-dark:
Ex:
<body>
<div class="container">
<h2>Alerts</h2>
<p>Alerts are created with the .alert class, followed by a contextual color classes:</p>
<div class="alert alert-success">
<strong>Success!</strong> This alert box could indicate a successful or positive action.
</div>
<div class="alert alert-info">
<strong>Info!</strong> This alert box could indicate a neutral informative change or action.
</div>
<div class="alert alert-warning">
<strong>Warning!</strong> This alert box could indicate a warning that might need attention.
</div>
<div class="alert alert-danger">
<strong>Danger!</strong> This alert box could indicate a dangerous or potentially negative
action.
</div>
<div class="alert alert-primary">
<strong>Primary!</strong> Indicates an important action.
</div>
<div class="alert alert-secondary">
<strong>Secondary!</strong> Indicates a slightly less important action.
</div>
<div class="alert alert-dark">
</div>
Button Sizes
Use the .btn-lg class for large buttons or .btn-sm class for small buttons:
Example:
<button type="button" class="btn btn-primary btn-lg">Large</button>
<button type="button" class="btn btn-primary">Default</button>
<button type="button" class="btn btn-primary btn-sm">Small</button>
</button>
</div>
Button Groups
Bootstrap 4 allows you to group a series of buttons together (on a single line) in a button group:
Example:
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
Vertical Button Groups
Bootstrap 4 also supports vertical button groups:
Example:
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
2.5 Images, Media Objects
To add images using bootstrap:
Example:
<div class="container">
<h2>Rounded Corners</h2>
<img src="i3.jpeg" class="rounded" alt="Nature Picture" width="300" height="200">
<img src="i4.jpeg" class="rounded-circle" alt="Nature Picture" width="300"
height="200">
<img src="i5.jpeg" class="img-thumbnail" alt="Nature Picture" width="300"
height="200">
</div>
<div class="container">
<h2>Aligning images</h2>
<img src="i6.jpeg" class="float-left" alt="Paris" width="304" height="236">
<img src="i7.jpeg" class="float-right" alt="Paris" width="304" height="236">
</div>
</div>
Media Objects
Bootstrap provides an easy way to align media objects (like images or videos) to the left or to the
right of some content. This can be used to display blog comments, tweets and so on…
Use a <div> element with the .media class to create a container for media objects.
Use the .media-left class to align the media object (image) to the left, or the .media-right class to
align it to the right.
Text that should appear next to the image, is placed inside a container with class="media-body".
Additionally, you can use .media-heading for headings.
2.6 Pagination
If you have a web site with lots of pages, you may wish to add some sort of pagination to each
page.
To create a basic pagination, add the .pagination class to an <ul> element. Then add the .page-
item to each <li> element and add the .page-link class to each link <a> inside <li>.
The .active class is used to "highlight" the current page:
The .disabled class is used for un-clickable links
Example:
<ul class="pagination">
<li class="page-item"><a class="page-link" href="home.html">Previous</a></li>
<li class="page-item"><a class="page-link" href="button.html">1</a></li>
<li class="page-item active"><a class="page-link" href="images_bs.html">2</a></li>
<li class="page-item"><a class="page-link" href="colors.html">3</a></li>
<li class="page-item"><a class="page-link" href="first_bootstrap.html">Next</a></li>
</ul>
Example:
<style>
.fakeimg {
height: 200px;
background: #aaa;
}
</style>
</head>
<body>
</body>
</html>