Bootstrap
Bootstrap
PIYUSH MISHRA
What is Bootstrap?
Bootstrap is a free front-end framework for
faster and easier web development
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 also gives you the ability to
easily create responsive designs
Bootstrap History
Bootstrap was developed by Mark Otto and
Jacob Thornton at Twitter, and released as an
open-source product in August 2011 on
GitHub.
Why Use Bootstrap?
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
Browser compatibility: Bootstrap is
compatible with all modern browsers (Chrome,
Firefox, Internet Explorer, Safari, and Opera)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
You should include the following <meta> element in all your web pages:
This gives the browser instructions on how to control the page's dimensions and scaling.
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.0 part sets the initial zoom level when the page is first loaded by the browser.
Here is an example of a web page without the viewport meta tag, and the same web page with the viewport meta
tag:
Tip: If you are browsing this page with a phone or a tablet, you can click on the two links below to see the
difference.
span 4 span 4 s
span 4 span 8
span 6 span 6
span 12
Grid Classes
The Bootstrap grid system has four classes:
xs (for phones)
sm (for tablets)
md (for desktops)
lg (for larger desktops)
The classes above can be combined to create more dynamic and flexible
layouts.
<div class="row">
</div>
Striped Rows
The .table-striped class adds zebra-stripes to a table:
Bordered Table
The .table-bordered class adds borders on all sides of the
table and cells:
Hover Rows
The .table-hover class adds a hover effect (grey background
color) on table rows:
Condensed Table
The .table-condensed class makes a table more compact
by cutting cell padding in half:
Alerts
Bootstrap provides an easy way to create predefined alert messages:
Success! This alert box indicates a successful or positive action.
Warning! This alert box indicates a warning that might need attention.
Alerts are created with the .alert class, followed by one of the four contextual
classes .alert-success, .alert-info, .alert-warning or .alert-
danger:
Example
<div class="alert alert-success">
<strong>Success!</strong> Indicates a
successful or positive action.
</div>
<div class="alert alert-info">
<strong>Info!</strong> Indicates a neutral informative change or
action.
</div>
Button Styles
Bootstrap provides seven styles of
buttons:
To achieve the button styles above,
Bootstrap has the following classes:
.btn-default
.btn-primary
.btn-success
.btn-info
.btn-warning
.btn-danger
.btn-link
The following example shows the code for the different button styles:
Example
Button Sizes
Bootstrap provides four button sizes:
Large, Medium, Small, XSmall
The classes that define the different sizes are:
.btn-lg
.btn-md
.btn-sm
.btn-xs
Bootstrap Forms
Bootstrap's Default Settings
Form controls automatically receive some global
styling with Bootstrap:
All textual <input>, <textarea>,
and <select> elements with class .form-
control have a width of 100%.
<form>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btnbtn-default">Submit</button>
</form>
When used together with the <label> element, the for attribute specifies
which form element a label is bound to.
</div>
</div>
Example Explained
The "Trigger" part:
To trigger the modal window, you need to use a button or a link.
Then include the two data-* attributes:
The parent <div> of the modal must have an ID that is the same as the value of
the data-target attribute used to trigger the modal ("myModal").
The .modal class identifies the content of <div> as a modal and brings focus to
it.
The .fade class adds a transition effect which fades the modal in and out.
Remove this class if you do not want this effect.
The .modal-dialog class sets the proper width and margin of the modal.
modal-sm
The "Modal content" part:
The .modal-header class is used to define the style for the header of the
modal. The <button> inside the header has a data-
dismiss="modal" attribute which closes the modal if you click on it.
The .close class styles the close button, and the .modal-title class styles
the header with a proper line-height.
The .modal-body class is used to define the style for the body of the modal.
Add any HTML markup here; paragraphs, images, videos, etc.
The .modal-footer class is used to define the style for the footer of the
modal. Note that this area is right aligned by default.
<nav
A standard navigation bar is created with
class="navbar navbar-default">.
The following example shows how to add a navigation bar to the top of the page
In the following example we insert a "Sign Up" button and a "Login" button to
the right in the navigation bar. We also add a glyphicon on each of the two new
buttons:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</nav>
Navbar Buttons
To add buttons inside the navbar, add the .navbar-btn class on a Bootstrap button:
Example
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
<button class="btn btn-danger navbar-btn">Button</button>
</div>
</nav>
Navbar Forms
To add form elements inside the navbar, add the .navbar-form class to a form
element and add an input(s). Note that we have added a .form-group class to
the div container holding the input. This adds proper padding if you have more
than one inputs (you will learn more about this in the Forms chapter).
Example
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
</ul>
<form class="navbar-form navbar-
left" action="/action_page.php">
<div class="form-group">
<input type="text" class="form-control" placeholde
r="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</nav>
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 .navbar-fixed-top class makes the navigation bar fixed at the top:
<div class="item">
<img src="chicago.jpg" alt="Chicago">
</div>
<div class="item">
<img src="ny.jpg" alt="New York">
</div>
</div>
Example Explained
The outermost <div>:
Carousels require the use of an id (in this case id="myCarousel") for carousel
controls to function properly.