Bootstrap 4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Bootstrap

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.

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

How to Use Bootstrap with HTML?

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 via CDN:


<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.0/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></scri
pt><script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></s
cript>

If you have downloaded the precompiled Bootstrap,


<link rel="stylesheet" href="css/bootstrap.min.css">

bootstrap/
├── css/
│ ├── bootstrap.css
│ ├── bootstrap.css.map
│ ├── bootstrap.min.css
│ └── bootstrap.min.css.map
└── js/
├── bootstrap.js
└── bootstrap.min.js

Responsive meta tag:


Bootstrap is developed mobile first, a strategy in which we optimize code for mobile devices
first and then scale up components as necessary using CSS media queries. To ensure
proper rendering and touch zooming for all devices, add the responsive viewport meta
tag to your <head>.
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-
fit=no">

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 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

Bootstrap Grids:
Bootstrap Grid System

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


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

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>

<p>The .table-condensed class makes a table more compact by cutting cell


padding in half:</p>
<table class="table table-condensed">

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>

<div class="container mt-3">

<h2>Flex</h2>

<p>To create a flexbox container and transform direct children into flex items,
use the d-flex class:</p>

<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> </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.

Responsive variations also exist for flex-direction.

• .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:

To create an inline flexbox container, use the d-inline-flex class.

<div class="d-inline-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>

Horizontal Direction

Use .flex-row to display the flex items horizontally (side by side). This is
default.

Tip: Use .flex-row-reverse to right-align the horizontal direction

Example:

<div class="d-flex flex-row bg-secondary">


<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>

<div class="d-flex flex-row-reverse bg-secondary">


<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>

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.

<div class="d-flex flex-column">


<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>

<div class="d-flex flex-column-reverse">


<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>

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>

Fill / Equal Widths


Example:

Use .flex-fill on flex items to force them into equal widths

<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>

You might also like