2. Design Website Using Bootstrap4
2. Design Website Using Bootstrap4
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
Example:
<div class="container">
<div class="row">
<div class="col-sm-4">
<h3>Column 1</h3>
<p>Loremipsumdolor..</p>
</div>
<div class="col-sm-4">
<h3>Column 2</h3>
<p>Loremipsumdolor..</p>
</div>
<div class="col-sm-4">
<h3>Column 3</h3>
<p>Loremipsumdolor..</p>
</div>
</div>
</div>
1 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Advantages of Bootstrap:
Easy to use: Anybody with just basic knowledge of HTML and CSS can
start using Bootstrap
jQuery
Bootstrap uses jQuery for JavaScript plugins (like modals, tooltips, etc).
However, if you just use the CSS part of Bootstrap, you don't need jQuery.
Containers
2 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Bootstrap Grid System
If you do not want to use all 12 columns individually, you can group the columns
together to create wider columns:
span 1 span span span span span span span span span span span
1 1 1 1 1 1 1 1 1 1 1
span 4 span 8
span 6 span 6
span 12
Grid Classes
The classes above can be combined to create more dynamic and flexible layouts.
3 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Basic Structure of a Bootstrap Grid
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
...
</div>
First; create a row (<div class="row">). Then, add the desired number of
columns (tags with appropriate .col-*-* classes). Note that numbers in .col-*-
* should always add up to 12 for each row.
.col-sm-4
.col-sm-4
.col-sm-4
The following example shows how to get a three equal-width columns starting at
tablets and scaling to large desktops. On mobile phones or screens that are less
than 768px wide, the columns will automatically stack:
Example
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-4">.col-sm-4</div>
</div>
.col-sm-4
.col-sm-8
4 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
The following example shows how to get two various-width columns starting at
tablets and scaling to large desktops:
Example
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-8">.col-sm-8</div>
</div>
A basic Bootstrap table has a light padding and only horizontal dividers.
Example
Striped Rows
Example
5 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Bordered Table
The .table-bordered class adds borders on all sides of the table and cells:
Example
Contextual Classes
Contextual classes can be used to color table rows (<tr>) or table cells (<td>):
Example
Alerts
6 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
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
Horizontal form
Inline form
7 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
The following example creates a vertical form with two input fields, one
checkbox, and a submit button:
Example
<form action="/action_page.php">
<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>
In an inline form, all of the elements are inline, left-aligned, and the labels are
alongside.
Note: This only applies to forms within viewports that are at least 768px wide!
The following example creates an inline form with two input fields, one checkbox,
and one submit button:
Example
A horizontal form means that the labels are aligned next to the input field
(horizontal) on large and medium screens. On small screens (767px and below),
it will transform to a vertical form (labels are placed on top of each input).
Tip: Use Bootstrap's predefined grid classes to align labels and groups of form
controls in a horizontal layout.
The following example creates a horizontal form with two input fields, one
checkbox, and one submit button.
Example
9 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" placeholder="Enter
password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btnbtn-default">Submit</button>
</div>
</div>
</form>
Button Styles
Bootstrap provides different styles of buttons:
To achieve the button styles above, Bootstrap has the following classes:
.btn
.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
10 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-link">Link</button>
Bootstrap Images:
Rounded Corners
Circle:
Responsive Images:
11 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Bootstrap Pagination:
If you have a web site with lots of pages, you may wish to add some sort of
pagination to each page.
Example
<ul class="pagination">
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
</ul>
Active State
Add class .active to let the user know which page he/she is on:
Example
<ul class="pagination">
<li><a href="#">1</a></li>
<li class="active"><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
</ul>
Disabled State
A disabled link cannot be clicked:
Add class .disabled if a link for some reason is disabled:
Example
<ul class="pagination">
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li class="disabled"><a href="#">4</a></li>
<li><a href="#">5</a></li>
</ul>
12 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Pagination Sizing
Pagination blocks can also be sized to a larger size or a smaller size:
Add class .pagination-lg for larger blocks or .pagination-sm for smaller blocks:
Example
Bootstrap Theme:
This page will show you how to build a Bootstrap theme from scratch.
We will start with a simple HTML page, and then add more and more
components, until we have a fully functional, personal and responsive website.
The result will look like this, and you are free to modify, save, share, use or do
whatever you want with it:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Theme Simply Me</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
13 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
</head>
<body>
<h3>Who Am I?</h3>
<img src="bird.jpg" alt="Bird">
<h3>I'm an adventurer</h3>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Theme Simply Me</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1
/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"
></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.mi
n.js"></script>
</head>
<body>
<div class="container-fluid">
<h3>Who Am I?</h3>
<img src="bird.jpg" alt="Bird">
<h3>I'm an adventurer</h3>
</div>
</body>
</html>
14 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Add Background Color and Center Text
1. Add a custom class (.bg-1) to the container to add a background color.
2. Add the .text-center class to center the text inside the container:
Example
<head>
<style>
.bg-1 {
background-color: #1abc9c; /* Green */
color: #ffffff;
}
</style>
</head>
<body>
<div class="container-fluid bg-1 text-center">
<h3>Who Am I?</h3>
<img src="bird.jpg" alt="Bird">
<h3>I'm an adventurer</h3>
</div>
</body>
Circle Image
Shape the image to a circle with the .img-circle class:
Example
More Content
Add more content and put it inside new containers:
Example
<head>
<style>
.bg-1 {
background-color: #1abc9c; /* Green */
color: #ffffff;
}
.bg-2 {
background-color: #474e5d; /* Dark Blue */
color: #ffffff;
15 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
}
.bg-3 {
background-color: #ffffff; /* White */
color: #555555;
}
</style>
</head>
<body>
Add Padding
Lets make the containers look good by adding some padding:
Example
<style>
.container-fluid {
padding-top: 70px;
padding-bottom: 70px;
}
</style>
16 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Add a Button
Add a button to the mid container:
Example
Add an Icon
Add a Search icon on the "Search" button:
Example
Example
17 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Make the Images Responsive
Add the .img-responsive class to all images.
If you want the image to span the entire width of the screen when it starts to
stack, add width:100% to the image.
When opening the example, remember to resize the screen to see the responsive
effect:
Example
18 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Add a Navbar
Add a standard navigation bar at the top of the page with and make it collapsible
on smaller screens:
Example
Example
.navbar {
padding-top: 15px;
padding-bottom: 15px;
border: 0;
border-radius: 0;
margin-bottom: 0;
font-size: 12px;
letter-spacing: 5px;
}
.navbar-nav li a:hover {
color: #1abc9c !important;
}
19 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat
Add a Footer
Add a footer and use CSS to style it:
Example
<style>
.bg-4 {
background-color: #2f2f2f;
color: #ffffff;
}
</style>
Final Touch
Personalize your Theme by adding a font that you like. We have used
"Montserrat" from Google's Font Library.
Example
body {
font: 20px "Montserrat", sans-serif;
line-height: 1.8;
color: #f5f6f7;
}
p {font-size: 16px;}
We have also created a "helper" margin class to add extra space where we think
it's needed; usually after each <h3> and <img> element.
Example
20 Prepared By:
Prof. Himanshu Mishra – SDJ International College,Surat