0% found this document useful (0 votes)
56 views29 pages

Web Lecture5

Bootstrap is a free front-end framework for building responsive, mobile-first sites. It includes HTML and CSS templates for common elements like navigation, buttons, forms, and more. Bootstrap uses a 12-column grid system and responsive design to automatically adapt layouts for different screen sizes. Developers can include Bootstrap via a content delivery network for fast loading or download it directly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views29 pages

Web Lecture5

Bootstrap is a free front-end framework for building responsive, mobile-first sites. It includes HTML and CSS templates for common elements like navigation, buttons, forms, and more. Bootstrap uses a 12-column grid system and responsive design to automatically adapt layouts for different screen sizes. Developers can include Bootstrap via a content delivery network for fast loading or download it directly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Web Development

Lecture 5
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
What is Responsive Web Design?
• Responsive web design is about creating web sites which
automatically adjust themselves to look good on all devices, from
small phones to large desktops.

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.
• In June 2014 Bootstrap was the No.1 project 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
• Mobile-first approach: In Bootstrap 3, mobile-first styles are part of
the core framework
• Browser compatibility: Bootstrap is compatible with all modern
browsers (Chrome, Firefox, Internet Explorer, Edge, Safari, and Opera)
Bootstrap Versions

• This tutorial follows Bootstrap 3, which was released in 2013. However, we


also cover newer versions; Bootstrap 4 (released 2018) and Bootstrap 5
(released 2021).
• Bootstrap 5 is the newest version of Bootstrap; with new components, faster
stylesheets, more responsiveness etc. It supports the latest, stable releases of
all major browsers and platforms. However, Internet Explorer 11 and down is
not supported.
• The main differences between Bootstrap 5 and Bootstrap 3 & 4, is that
Bootstrap 5 has switched to JavaScript instead of jQuery.
Where to Get Bootstrap?

• There are two ways to start using Bootstrap on your own web site.
• You can:
• Download Bootstrap from getbootstrap.com
• Include Bootstrap from a CDN
• Downloading Bootstrap
If you want to download and host Bootstrap yourself, go to 
getbootstrap.com, and follow the instructions there.
• Bootstrap CDN
If you don't want to download and host Bootstrap yourself, you can
include it from a CDN (Content Delivery Network).
MaxCDN provides CDN support for Bootstrap's CSS and JavaScript.
MaxCDN:

• <!-- Latest compiled and minified CSS -->


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/
3.4.1/css/bootstrap.min.css">

<!-- jQuery library -->


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/
jquery.min.js"></script>

<!-- Latest compiled JavaScript -->


<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/
bootstrap.min.js"></script>
• One advantage of using the Bootstrap CDN:
Many users already have downloaded Bootstrap from MaxCDN when visiting
another site. As a result, it will be loaded from cache when they visit your
site, which leads to faster loading time. Also, most CDN's will make sure that
once a user requests a file from it, it will be served from the server closest to
them, which also leads to faster loading time.

• 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.
Create First Web Page With Bootstrap

1. Add the HTML5 doctype

• Bootstrap uses HTML elements and CSS properties that require the HTML5
doctype.
• Always include the HTML5 doctype at the beginning of the page, along with
the lang attribute and the correct character set:
• <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
</html>
2. Bootstrap 3 is mobile-first
Bootstrap 3 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 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
Two Basic Bootstrap Pages
The following example shows the code for a basic Bootstrap page
(with a responsive fixed width container):
<!DOCTYPE html> <body>
<html lang="en">
<head>
<title>Bootstrap Example</title> <div class="container">
<meta charset="utf-8">
<h1>My First Bootstrap Page</h1>
<meta name="viewport" content="width=device-width,
initial-scale=1"> <p>This part is inside a .container class.</p>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/ <p>The .container class provides a
bootstrap.min.css"> responsive fixed width container.</p>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery. </div>
min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bo </body>
otstrap.min.js"></script>
</head>
</html>
The following example shows the code for a basic Bootstrap page (with
a full width container):

<!DOCTYPE html>
<html lang="en">
<body>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
<div class="container-
  <meta name="viewport" content="width=dev fluid">
ice-width, initial-scale=1">
  <link rel="stylesheet" href="https://max   <h1>My First Bootstrap
cdn.bootstrapcdn.com/bootstrap/3.4.1/css/ Page</h1>
bootstrap.min.css">
  <script src="https://   <p>This is some text.</p>
ajax.googleapis.com/ajax/libs/jquery/ </div>
3.6.4/jquery.min.js"></script>
  <script src="https://
maxcdn.bootstrapcdn.com/bootstrap/3.4.1/
js/bootstrap.min.js"></script>
</body>
</head> </html>
Bootstrap Grids

• Bootstrap's grid system 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:
Grid Classes

The Bootstrap grid system has four classes:


•xs (for phones - screens less than 768px wide)
•sm (for tablets - screens equal to or greater than 768px wide)
•md (for small laptops - screens equal to or greater than 992px wide)
•lg (for laptops and desktops - screens equal to or greater than 1200px wide)
The classes above can be combined to create more dynamic and flexible
layouts.
Basic Structure of a Bootstrap Grid

• The following is a basic structure of


a Bootstrap grid:
• <div class="row"> First; create a row (<div class="row">).
  <div class="col-*-*"></div> Then, add the desired number of columns (tags with
  <div class="col-*-*"></div> appropriate .col-*-* classes).
</div> Note that numbers in .col-*-* should always add up
to 12 for each row.
<div class="row">
Below we have collected some examples of basic
  <div class="col-*-*"></div> Bootstrap grid layouts.
  <div class="col-*-*"></div>
  <div class="col-*-*"></div>
</div>
<div class="row">
  ...
</div>
• Three Equal Columns
• 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:
<body>
<!DOCTYPE html>
<html lang="en"> <div class="container-fluid">
<h1>Hello World!</h1>
<head> <p>Resize the browser window to see the effect.</p>
<title>Bootstrap Example</title> <p>The columns will automatically stack on top of each other
when the screen is less than 768px wide.</p>
<meta charset="utf-8"> <div class="row">
<meta name="viewport" <div class="col-sm-4" style="background-
content="width=device-width, initial-scale=1"> color:lavender;">.col-sm-4
<h1>this</h1>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstr
</div>
ap/3.4.1/css/bootstrap.min.css">
<div class="col-sm-4" style="background-
<script color:lavenderblush;">.col-sm-4</div>
src="https://ajax.googleapis.com/ajax/libs/jquer <div class="col-sm-4" style="background-
y/3.6.4/jquery.min.js"></script> color:lavender;">.col-sm-4</div>
</div>
<script
</div>
src="https://maxcdn.bootstrapcdn.com/bootstra
p/3.4.1/js/bootstrap.min.js"></script>
</body>
</head> </html>
Two Unequal Columns

<div class="row">
  <div class="col-sm-4">.col-sm-4</div>
  <div class="col-sm-8">.col-sm-8</div>
</div>
<body>
<!DOCTYPE html>
<html lang="en"> <div class="container-fluid">
<head> <h1>Hello World!</h1>
<title>Bootstrap Example</title> <p>Resize the browser window to see the
effect.</p>
<meta charset="utf-8">
<p>The columns will automatically stack on top of
<meta name="viewport" each other when the screen is less than 768px
content="width=device-width, initial-scale=1"> wide.</p>
<link rel="stylesheet" <div class="row">
href="https://maxcdn.bootstrapcdn.com/bootstr <div class="col-sm-4" style="background-
ap/3.4.1/css/bootstrap.min.css"> color:lavender;">.col-sm-4</div>
<script <div class="col-sm-8" style="background-
src="https://ajax.googleapis.com/ajax/libs/jquer color:lavenderblush;">.col-sm-8</div>
y/3.6.4/jquery.min.js"></script> </div>
<script </div>
src="https://maxcdn.bootstrapcdn.com/bootstra
p/3.4.1/js/bootstrap.min.js"></script> </body>
</head> </html>
No gutters

• <div class="row row-no-gutters">
  <div class="col-sm-3">.col-sm-3</div>
  <div class="col-sm-6">.col-sm-6</div>
  <div class="col-sm-3">.col-sm-3</div>
</div>
Two Columns With Two Nested Columns
The following example shows how to get two columns starting at tablets and scaling to large
desktops, with another two columns (equal widths) within the larger column (at mobile
phones, these columns and their nested columns will stack):

<!DOCTYPE html> <body>


<html lang="en">
<head> <div class="container-fluid">
<title>Bootstrap Example</title> <h1>Hello World!</h1>
<meta charset="utf-8">
<p>Resize the browser window to see the effect.</p>
<meta name="viewport" content="width=device-width,
initial-scale=1"> <div class="row">
<link rel="stylesheet" <div class="col-sm-8" style="background-color:lavender;">.col-sm-8
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/c <div class="row">
ss/bootstrap.min.css"> <div class="col-sm-6" style="background-color:lightcyan;">.col-sm-
<script
<div class="col-sm-6" style="background-color:lightgray;">.col-sm-6
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jq
uery.min.js"></script> </div>
<script </div>
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js <div class="col-sm-4" style="background-color:lavenderblush;">.col-s
/bootstrap.min.js"></script>
</div>
</head>
</div>

</body>
Mixed: Mobile And Desktop
• The Bootstrap grid system has
• <div class="row"> four classes: xs (phones), sm
  <div class="col-xs-9 col-md-7">.col-
xs-9 .col-md-7</div>
(tablets), md (desktops), and lg
  <div class="col-xs-3 col-md-5">.col- (larger desktops). The classes can
xs-3 .col-md-5</div>
</div> be combined to create more
dynamic and flexible layouts.
<div class="row">
  <div class="col-xs-6 col-md-10">.col-
xs-6 .col-md-10</div>
  <div class="col-xs-6 col-md-2">.col-
xs-6 .col-md-2</div>
</div> • Tip: Each class scales up, so if
<div class="row"> you wish to set the same widths
  <div class="col-xs-6">.col-xs-6</div>
  <div class="col-xs-6">.col-xs-6</div>
for xs and sm, you only need to
</div> specify xs.
Mixed: Mobile, Tablet And Desktop

• <div class="row">
  <div class="col-xs-7 col-sm-6 col-lg-8">.col-xs-
7 .col-sm-6 .col-lg-8</div>
  <div class="col-xs-5 col-sm-6 col-lg-4">.col-xs-
5 .col-sm-6 .col-lg-4</div>
</div>

<div class="row">
  <div class="col-xs-6 col-sm-8 col-lg-10">.col-xs-6
.col-sm-8 .col-lg-10</div>
  <div class="col-xs-6 col-sm-4 col-lg-2">.col-xs-
6 .col-sm-4 .col-lg-2</div>
</div>
Clear Float
Clear floats (with the .clearfix class) at specific breakpoints to prevent strange wrapping with uneven content:

Example
<div class="row">
  <div class="col-xs-6 col-sm-3">
    Column 1
    <br>
    Resize the browser window to see the effect.
  </div>
  <div class="col-xs-6 col-sm-3">Column 2</div>
  <!-- Add clearfix for only the required viewport -->
  <div class="clearfix visible-xs"></div>
  <div class="col-xs-6 col-sm-3">Column 3</div>
  <div class="col-xs-6 col-sm-3">Column 4</div>
</div>
<body>

<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-xs-6 col-sm-3" style="background-color:lavender;">
Column 1<br>
Resize the browser window to see the effect. Also try to remove the div clearfix line and see what happens.
</div>
<div class="col-xs-6 col-sm-3" style="background-color:lavenderblush;">Column 2</div>
<!-- Add clearfix for only the required viewport -->
<div class="clearfix visible-xs"></div>
<div class="col-xs-6 col-sm-3" style="background-color:lightcyan;">Column 3</div>
<div class="col-xs-6 col-sm-3" style="background-color:lightgray;">Column 4</div>
</div>
</div>

</body>
</html>
Offsetting Columns
Move columns to the right using .col-md-offset-* classes. These classes increase the left margin of a
column by * columns:

Example
<div class="row">
  <div class="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div>
  <div class="col-sm-5 col-sm-offset-2 col-md-6 col-md-offset-0">
</div>
<

<body>

<div class="container-fluid">
<h1>Offsetting Columns</h1>
<p>Resize the browser window to see the effect.</p>
<div class="row" style="background-color:lavender;">
<div class="col-sm-5 col-md-6" style="background-color:lightgray;">.col-sm-5 .col-md-6</div>
<div class="col-sm-5 col-sm-offset-2 col-md-6 col-md-offset-0" style="background-color:lightcyan;">.col-sm-5 .col-
sm-offset-2 .col-md-6 .col-md-offset-0</div>
</div>
</div>

</body>
</html>
Push And Pull - Change Column Ordering
Change the order of the grid columns with .col-md-push-* and .col-md-pull-* classes:

Example
<div class="row">
  <div class="col-sm-4 col-sm-push-8">.col-sm-4 .col-sm-push-8</div>
  <div class="col-sm-8 col-sm-pull-4">.col-sm-8 .col-sm-pull-4</div>
</div>

<body>

<div class="container-fluid">
<h1>Push and Pull</h1>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="col-sm-4 col-sm-push-8" style="background-
color:lavender;">.col-sm-4 .col-sm-push-8</div>
<div class="col-sm-8 col-sm-pull-4" style="background-
color:lavenderblush;">.col-sm-8 .col-sm-pull-4</div>
</div>
</div>

</body>
</html>

You might also like