Lesson 5.1 - Bootstrap

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

Finals - Bootstrap

Bootstrap Overview
What is Twitter Bootstrap?
Bootstrap is a sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It
uses HTML, CSS and Javascript.

History
Bootstrap was developed by Mark Otto and Jacob Thornton at Twitter. It was released as an open source product in
August 2011 on GitHub.

Why use Bootstrap?


 Mobile first approach: Since Bootstrap 3, the framework consists of Mobile first styles throughout the entire library
instead of in separate files.
 Browser Support: It is supported by all popular browsers.
 Responsive design: Bootstrap's responsive CSS adjusts to Desktops,Tablets and Mobiles. More about responsive
design in the chapter Bootstrap Responsive Design

It also provides web based customization. And best of all it is an open source.

HTML Template

<!DOCTYPE html>
<html>

<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media
queries -->
<!-- WARNING: Respond.js doesn't work if you view the page
via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/
html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/
respond.min.js"></script>
<![endif]-->
</head>

<body>
<h1>Hello, world!</h1>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->


<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files
as needed -->
<script src="js/bootstrap.min.js"></script>
</body>

</html>

1
Finals - Bootstrap

Grid System
What is Bootstrap Grid System?
Bootstrap includes a responsive, mobile first fluid grid system that appropriately scales up to 12 columns as the device or
viewport size increases. It includes predefined classes for easy layout options, as well as powerful mixins for generating
more semantic layouts

Mobile First Strategy


 Content. Determine what is most important.
 Layout. Design to smaller widths first. Base CSS address mobile device first;media queries address for
tablet,desktops.
 Progressive Enhancement. Add elements as screen size increases.

Working of Bootstrap Grid System


Grid systems are used for creating page layouts through a series of rows and columns that house your content. Here's
how the Bootstrap grid system works:

 Rows must be placed within a .container class for proper alignment and padding.
 Use rows to create horizontal groups of columns.
 Content should be placed within columns, and only columns may be immediate children of rows.
 Predefined grid classes like .row and .col-xs-4 are available for quickly making grid layouts. Columns create
gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via
negative margin on .rows.
 Grid columns are created by specifying the number of twelve available columns you wish to span. For example,
three equal columns would use three .col-xs-4.

Media Queries
Media query is a really fancy term for "conditional CSS rule". It simply applies some CSS based on certain conditions set
forth. If those conditions are met, the style is applied.

Media Queries in Bootstrap allow you to move, show and hide content based on viewport size. Following media queries
are used in LESS files to create the key breakpoints in the Bootstrap grid system.

 
/* Extra small devices (phones, less than 768px) */ 
/* No media query since this is the default in Bootstrap */ 
 
/* Small devices (tablets, 768px and up) */ 
@media (min-width: @screen-sm-min) { ... }
 
/* Medium devices (desktops, 992px and up) */ 
@media (min-width: @screen-md-min) { ... }

/* Large devices (large desktops, 1200px and up) */ 
@media (min-width: @screen-lg-min) { ... }
 
Occasionally these are expanded to include a max‐width to limit CSS to a narrower set of devices. 
 
@media (max-width: @screen-xs-max) { ... }
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... }
@media (min-width: @screen-lg-min) { ... }
 
 
2
Finals - Bootstrap

 
 
Media queries have two parts, a device specification and then a size rule. In the above case, the following rule is set:

Lets consider this line:


@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }
 
For all devices no matter what kind with min-width: @screen-sm-min if the width of the screen gets smaller than @screen-
sm-max, then do something.

Grid options
The following table summarizes aspects of how Bootstrap grid system works across multiple devices:

Basic Grid Structure


Following is basic structure of Bootstrap grid:

 
<div class="container">
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">...</div>
</div>
<div class="container">

3
Finals - Bootstrap

Responsive column resets


With the four tiers of grids available you're bound to run into issues where, at certain breakpoints, your columns don't
clear quite right as one is taller than the other. To fix that, use a combination of a class .clearfix and the responsive utility
classes as shown in the following example:

<div class="container">
<div class="row" >
<div class="col-xs-6 col-sm-3" style="background-color: #dedef8; box-shadow:
inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div class="col-xs-6 col-sm-3"
style="background-color: #dedef8;box-shadow:
inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut.
</p>
</div>

<div class="clearfix visible-xs"></div>

<div class="col-xs-6 col-sm-3"


style="background-color: #dedef8;
box-shadow:inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.
</p>
</div>
<div class="col-xs-6 col-sm-3"
style="background-color: #dedef8;box-shadow:
inset 1px -1px 1px #444, inset -1px 1px 1px #444;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim
</p>
</div>
</div>
</div>

Offset columns
Offsets are a useful feature for more specialized layouts. They can be used to push columns over for more spacing, for
example. The .col-xs=* classes don’t support offsets, but they are easily replicated by using an empty cell.

To use offsets on large displays, use the .col-md-offset-* classes. These classes increase the left margin of a column by *
columns where * range from 1 to 11. If we have <div class="col-md-6">..</div>, we will center this using class .col-md-
offset-3.

<div class="container">
<div class="row" >
<div class="col-xs-6 col-md-offset-3" style="background-color: #dedef8;box-
shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;"> </div>
</div>
</div>

4
Finals - Bootstrap

Bootstrap CSS Overview


Mobile First
You need to add the viewport meta tag to the <head> element, to ensure proper rendering and touch zooming on
mobile devices.

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Responsive images
Bootstrap 3 allows to make the images responsive by adding a class .img-responsive to the <img> tag.

<img src="..." class="img-responsive" alt="Responsive image">

Dropdowns
Dropdown menus are toggleable, contextual menus for displaying links in a list format. To use dropdown, just wrap the
dropdown menu within the class .dropdown.

<div class="dropdown">
<button type="button" class="btn dropdown-toggle"
id="dropdownMenu1" data-toggle="dropdown">
Topics
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Java</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Data Mining</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#"> Data Communication/Networking
</a>
</li>
<li role="presentation" class="divider"></li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="#">Separated link</a>
</li>
</ul>
</div>

Glyphicons
Glyphicons are icon fonts which you can use in your web projects. Glyphicons Halflings are not free and require
licensing, however their creator has made them available for Bootstrap projects free of cost.

Usage To use the icons, simply use the following code just about anywhere in your code. Leave a space between the icon
and text for proper padding.

<button type="button" class="btn btn-default btn-lg">


<span class="glyphicon glyphicon-user"></span> User
</button>

You might also like