Bootstrap 4
Bootstrap 4
Bootstrap 4
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.
To begin with Bootstrap, first, you need to have Bootstrap installed on your computer. you
can download Bootstrap from getbootstrap.com or include Bootstrap via CDN if you don't
want to download Bootstrap locally.If you have downloaded Bootstrap locally on your
computer, the following would be the file structure.
bootstrap/
├── css/
│ ├── bootstrap.css
│ ├── bootstrap.css.map
│ ├── bootstrap.min.css
│ └── bootstrap.min.css.map
└── js/
├── bootstrap.js
└── bootstrap.min.js
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.
Containers:
Bootstrap Grids:
Bootstrap Grid System
If you do not want to use all 12 columns individually, you can group the
columns together to create wider columns.
Grid Classes
The classes above can be combined to create more dynamic and flexible
layouts.
Grid Options
The following table summarizes how the Bootstrap grid system works across
multiple devices:
Bootstrap table:
Basic table in bootstrap.
1. Striped Rows:
<div class="container">
<h2>Striped Rows</h2>
<p>The .table-striped class adds zebra-stripes to a table:</p>
<table class="table table-striped">
2. Bordered Table:
<div class="container">
<h2>Bordered Table</h2>
<p>The .table-bordered class adds borders to a table:</p>
<table class="table table-bordered"> <h2>Bordered Table</h2>
<p>The .table-bordered class adds borders to a table:</p>
<table class="table table-bordered">
3. Hover Rows:
<div class="container">
<h2>Hover Rows</h2>
<p>The .table-hover class enables a hover state on table rows:</p>
<table class="table table-hover">
4. Condensed Table
<div class="container">
<h2>Condensed Table</h2>
5. Contextual Classes
<div class="container">
<h2>Contextual Classes</h2>
<p>Contextual classes can be used to color table rows or table cells.
The classes that can be used are: .active, .success, .info, .warning, and
.danger.</p>
<table class="table">
6. Responsive Tables
Syntax:
<div class="container">
<h2>Table</h2>
<p>The .table-responsive class creates a responsive table which will
scroll horizontally on small devices (under 768px). When viewing on
anything larger than 768px wide, there is no difference:</p>
<div class="table-responsive">
Task Create this example using bootstrap classes.
Bootstrap 4 Flexbox:
The biggest difference between Bootstrap 3 and Bootstrap 4 is that Bootstrap 4
now uses flexbox, instead of floats, to handle the layout. The Flexible Box
Layout Module, makes it easier to design flexible responsive layout structure
without using float or positioning.
Example:
<body>
<h2>Flex</h2>
<p>To create a flexbox container and transform direct children into flex items,
use the d-flex class:</p>
</div> </div>
Bootstrap FlexBox:
You set the direction of flex items in a flex container with direction utilities. In
most cases, you can omit the horizontal class here as the browser default
is row. However, you may encounter situations where you needed to explicitly
set this value (like responsive layouts). Use .flex-row to set a horizontal
direction (the browser default), or .flex-row-reverse to start the horizontal
direction from the opposite side.
• .flex-row
• .flex-row-reverse
• .flex-column
• .flex-column-reverse
• .flex-sm-row
• .flex-sm-row-reverse
• .flex-sm-column
• .flex-sm-column-reverse
• .flex-md-row
• .flex-md-row-reverse
• .flex-md-column
• .flex-md-column-reverse
• .flex-lg-row
• .flex-lg-row-reverse
• .flex-lg-column
• .flex-lg-column-reverse
• .flex-xl-row
• .flex-xl-row-reverse
• .flex-xl-column
• .flex-xl-column-reverse
Example:
To create a flexbox container and to transform direct children into flex items,
use the d-flex class:<div class="d-flex p-3 bg-secondary text-white">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Example:
Horizontal Direction
Use .flex-row to display the flex items horizontally (side by side). This is
default.
Example:
Vertical Direction
Example:
Use .flex-column to display the flex items vertically (on top of each other),
or .flex-column-reverse to reverse the vertical direction.
Justify Content
Example:
Use the .justify-content-* classes to change the alignment of flex items. Valid
classes are start (default), end, center, between or around.
<div class="d-flex justify-content-start">...</div>
<div class="d-flex justify-content-end">...</div>
<div class="d-flex justify-content-center">...</div>
<div class="d-flex justify-content-between">...</div>
<div class="d-flex justify-content-around">...</div>
<div class="d-flex">
<div class="p-2 bg-info flex-fill">Flex item 1</div>
<div class="p-2 bg-warning flex-fill">Flex item 2</div>
<div class="p-2 bg-primary flex-fill">Flex item 3</div>
</div>
Grow
Use .flex-grow-1 on a flex item to take up the rest of the space. In the example
below, the first two flex items take up their necessary space, while the last item
takes up the rest of the available space.
<div class="d-flex">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary flex-grow-1">Flex item 3</div>
</div>