Bootstrap
Bootstrap
Web Programing
Bootstrap
Husain Dawoodi
System Analyst
UGC Computer Center, School of Computer Sciences
Responsive Web Design
• Responsive web design is about creating web pages that
look good on all devices!
• A responsive web design will automatically adjust for
different screen sizes and viewports.
• Responsive web design automatically adjust themselves to
look good on all devices, from small phones to large
desktop.
• Bootstrap is the most popular HTML, CSS, and JavaScript
framework for developing responsive, mobile-first
Overview of websites.
• Bootstrap is a free front-end framework for faster and
Bootstrap easier web development
• Bootstrap also gives you the ability to easily create
responsive designs
• 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
• <!DOCTYPE html>
2. Bootstrap is mobile-first
Page device).
• The initial-scale=1 part sets the initial zoom level when the page is
first loaded by the browser.
3. Containers
• Responsive Images:
• Images come in all sizes. So do screens.
Responsive images automatically adjust to fit the
size of the screen.
• Create responsive images by adding an .img-fluid
class to the <img> tag. The image will then scale
nicely to the parent element.
• The .img-fluid class applies max-width: 100%; and
height: auto; to the image:
<img class="img-fluid" src="img_chania.jpg" alt="Chania">
• A jumbotron indicates a big grey box for calling extra attention to some special content or
information
<div class="jumbotron">
<h1>Bootstrap Tutorial</h1>
<p>Bootstrap is the most popular HTML, CSS...</p>
</div>
Bootstrap • Full-width Jumbotron: If you want a full-width jumbotron without rounded borders, add the
.jumbotron-fluid class and a .container or .container-fluid inside of it
<div class="jumbotron jumbotron-fluid">
Jumbotron <div class="container">
<h1>Bootstrap Tutorial</h1>
<p>Bootstrap is the most popular HTML, CSS...</p>
</div>
</div>
Bootstrap Wells (v. 3)
Bootstrap </div>
Alerts
(Contd..)
Bootstrap Buttons
• The .btn classes can be used on <a>, <button>, or <input> elements
• <button type="button" class="btn">Basic</button>
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</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-dark">Dark</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-link">Link</button>
Bootstrap Buttons (Contd..)
• <button type="button" class="btn btn-outline-primary">Primary</button>
<button type="button" class="btn btn-outline-secondary">Secondary</button>
<button type="button" class="btn btn-outline-success">Success</button>
<button type="button" class="btn btn-outline-info">Info</button>
<button type="button" class="btn btn-outline-warning">Warning</button>
<button type="button" class="btn btn-outline-danger">Danger</button>
<button type="button" class="btn btn-outline-dark">Dark</button>
<button type="button" class="btn btn-outline-light text-dark">Light</button>
Bootstrap Buttons (Contd..)
• Button Sizes: Use the .btn-lg class for large buttons or .btn-sm class for
small buttons
• Block Level Buttons: Add class .btn-block to create a block level button
that spans the entire width of the parent element.
• Active/Disabled Buttons: A button can be set to an active (appear
pressed) or a disabled (unclickable) state. The class .active makes a
button appear pressed, and the disabled attribute makes a button
unclickable.
• Spinner Buttons:
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
Bootstrap Button Groups
• Bootstrap allows you to group a series of buttons
together (on a single line) in a button group.
• Use a <div> element with class .btn-group|-lg|-sm to
create a button group.
<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: Use the class
.btn-group-vertical to create a vertical button group
Bootstrap Badges
• Badges are used to add additional information to any content.
• Use the .badge class together with a contextual class (like
.badge-secondary) within <span> elements to create
rectangular badges
<h1>Example heading <span class="badge
badge-secondary">New</span></h1>
• Contextual Badges: Use any of the contextual classes (.badge-*)
to change the color of a badge
<span class="badge badge-primary">Primary</span>
• Pill Badges: Use the .badge-pill class to make the badges more
round
<span class="badge badge-pill
badge-primary">Primary</span>
• Badge inside an Element:
<button type="button" class="btn btn-primary">
Messages <span class="badge badge-light">4</span>
</button>
Bootstrap Progress Bars
• Basic Progress Bar: To create a default progress bar, add a .progress class to a container element and add the .progress-bar class to its child
element.
<div class="progress">
<div class="progress-bar" style="width:70%"></div>
</div>
• Striped Progress Bars: Use the .progress-bar-striped class to add stripes to the progress bars
<div class="progress">
<div class="progress-bar progress-bar-striped" style="width:40%"></div>
</div>
• Animated Progress Bar: Add the .progress-bar-animated class to animate the progress bar
<div class="progress-bar progress-bar-striped progress-bar-animated"style="width:40%"></div>
Bootstrap Progress Bars (Contd..)
• Multiple Progress Bars: Progress bars can also be stacked
<div class="progress">
<div class="progress-bar bg-success" style="width:40%">
Free Space
</div>
<div class="progress-bar bg-warning" style="width:10%">
Warning
</div>
<div class="progress-bar bg-danger" style="width:20%">
Danger
</div>
</div>
• Basic Pagination : To create a basic pagination, add the .pagination class to an <ul> element.
Then add the .page-item to each <li> element and a .page-link class to each link inside <li>
<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="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
• Pagination Sizing : Add class .pagination-lg for larger blocks or .pagination-sm for smaller
Bootstrap blocks
<ul class="pagination pagination-lg">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
Pagination <li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
• Pagination Alignment : To change the alignment of the pagination
<ul class="pagination justify-content-center" style="margin:20px 0">
<li class="page-item">...</li>
</ul>
<ul class="pagination justify-content-end" style="margin:20px 0">
<li class="page-item">...</li>
</ul>
Bootstrap List Groups
• To create a basic list group, use an <ul> element with class .list-group, and <li> elements
with class .list-group-item
<ul class="list-group">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>
• List Group With Linked Items: To create a list group with linked items, use <div> instead
of <ul> and <a> instead of <li>. Optionally, add the .list-group-item-action class if you
want a grey background color on hover
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">First item</a>
<a href="#" class="list-group-item list-group-item-action">Second item</a>
<a href="#" class="list-group-item list-group-item-action">Third item</a>
</div>
• Horizontal List Groups: Add the .list-group-horizontal class to .list-group to display items
horizontally
• Contextual Classes: .list-group-item-success, list-group-item-secondary,
list-group-item-info, list-group-item-warning, .list-group-item-danger,
.list-group-item-primary, list-group-item-dark and list-group-item-light
Bootstrap Dropdowns
• A dropdown menu is a toggleable menu that allows the
user to choose one value from a predefined list
<div class="dropdown">
<button type="button" class="btn btn-primary
dropdown-toggle" data-toggle="dropdown">
Dropdown button
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
</div>
</div>
• Dropdown Divider: .dropdown-divider class is used to
separate links inside the dropdown menu with a thin
horizontal border
• Dropdown Header: .dropdown-header class is used to
add headers inside the dropdown menu
• Dropdown Position: You can also create a "dropright"
or "dropleft" menu, by adding the .dropright or
.dropleft class to the dropdown element
• Dropup: you want the dropdown menu to expand
upwards instead of downwards, change the <div>
element with class="dropdown" to "dropup"
Bootstrap Collapse
• Basic Collapsible: Collapsible are useful when you want to hide and show large amount
of content
<button data-toggle="collapse" data-target="#demo">Collapsible</button>
<div id="demo" class="collapse">
Lorem ipsum dolor text....
</div>
• By default, the collapsible content is hidden. However, you can add the .show class to
show the content by default
Bootstrap Navigation Bar
• A navigation bar is a navigation header that is placed at the top of the page
• With Bootstrap, a navigation bar can extend or collapse, depending on the screen size
• A standard navigation bar is created with the .navbar class, followed by a responsive collapsing
class: .navbar-expand-xl|lg|md|sm (stacks the navbar vertically on extra large, large, medium or
small screens)
• To add links inside the navbar, use a <ul> element with class="navbar-nav". Then add <li>
elements with a .nav-item class followed by an <a> element with a .nav-link class
<!-- A grey horizontal navbar that becomes vertical on small screens -->
<nav class="navbar navbar-expand-sm bg-light">
<!-- Links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 3</a>
</li>
</ul>
</nav>
• Vertical Navbar: Remove the .navbar-expand-xl|lg|md|sm class to create a vertical navigation
bar
• Centered Navbar: Add the .justify-content-center class to center the navigation bar
Bootstrap Tabs
• Tabs are created with <ul class="nav nav-tabs">
<ul class="nav nav-tabs">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
• Pills are created with <ul class="nav nav-pills">. Also
mark the current page with <li class="active">
<ul class="nav nav-pills">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
</ul>
Bootstrap Pills
Bootstrap Forms
• Bootstrap Form Layouts: Bootstrap provides two types of form
layouts:
• Stacked (full-width) form
• Inline form (Add class .form-inline to the <form> element)
Bootstrap Form
Inputs
• Bootstrap supports the following form controls:
• input
• textarea
• checkbox
• radio
• select
• Use the .form-control class to style inputs with full-width and proper
padding
<div class="form-group">
<label for="usr">Name:</label>
<input type="text" class="form-control" id="usr">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
Bootstrap Form Inputs (Contd..)
• Bootstrap Checkboxes:
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="">Option 1
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="">Option 2
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="" disabled>Option 3
</label>
</div>
• Use the .form-check-inline class if you want the checkboxes to appear on the
same line
Bootstrap Form Inputs (Contd..)
• Bootstrap Radio Buttons:
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio">Option 1
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio">Option 2
</label>
</div>
<div class="form-check disabled">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio" disabled>Option 3
</label>
</div>
• Use the .form-check-inline class if you want the radio buttons to appear on the
same line
• Bootstrap Select List:
<div class="form-group">
<label for="sel1">Select list:</label>
<select class="form-control" id="sel1">
<option>1</option>
<option>2</option>
<option>3</option>
Bootstrap <option>4</option>
</select>
</div>
Form Inputs
(Contd..)
• Form Control File and Range: Add the .form-control-range
class to input type"range" or .form-control-file to input
type"file" to style a range control or a file field with full-width
<input type="range" class="form-control-range">
<input type="file" class="form-control-file border">
Bootstrap
Form Inputs
(Contd..)