40
Imran Ihsan Assistant Professor, Department of Computer Science Air University, Islamabad, Pakistan www.imranihsan.com Responsive Web Design – BootStrap Front-End UI: Bootstrap Responsive Design and Grid System

Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

  • Upload
    others

  • View
    20

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Imran IhsanAssistant Professor, Department of Computer ScienceAir University, Islamabad, Pakistanwww.imranihsan.com

Responsive Web Design – BootStrap

Front-End UI: Bootstrap

Responsive Design and Grid System

Page 2: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

What are Front-end UI Frameworks

Collection of ready-to-use HTML, CSS and

JavaScript templates for UI components:

Typography,

Forms, Buttons, Tables,

Navigations, Dropdowns, Alerts,

Modals, Tabs, Accordion,

Carousel etc.

Page 3: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Popular Front-end UI Frameworks

1. Bootstrap 6. Pure

2. Semantic-UI 7. Skeleton

3. Foundation 8. UIKit

4. Materialize 9. Milligram

5. Material UI 10. Susy

https://www.keycdn.com/blog/front-end-frameworks/

Page 4: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Why Front-End Web UI Frameworks?

Responsive web designMobile first

Cross-browser compatibilityDealing with quirks of browsers

Increased productivityEasy to get started

Community supportResources and web page templates

Page 5: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap Overview

Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile

first projects on the web

From the Bootstrap webpage

Page 6: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap Overview

Front-end framework for faster and easier web

development

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

Easily create responsive designs with mobile first approach

Page 7: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap History

First released in 2011

Mark Otto and Jacob Thornton

Current Production Version 4.1.3

The first comprehensive framework

Gained popularity very quickly

Page 8: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Setting up the Project Folder

Download the Bootstrap4-starter.zip and Unzip

Open a cmd window

Move to the conFusion folder and Type

npm install

Initialize a Git repository in the project folder

node_modules

Commit of your project folder to the Git repository with the message "Initial Setup".

Set up an online Git repository and synchronize your project folder with online repository.

Page 9: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Downloading Bootstrap

Use npm to fetch the Bootstrap files for use within your project

Npm install [email protected] –save

This will fetch the Bootstrap files and store is in your node_modules folder in a bootstrap folder.

The bootstrap->dist folder contains the precompiled Bootstrap CSS and JS files for use within your project.

Start your lite-server by typing npm start at the prompt.

Page 10: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Getting your Web Page Bootstrap Ready

Open the index.html file in your favorite text editor.

Insert the following code in the <head> of index.html

<!-- Required meta tags always come first -->

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<meta http-equiv="x-ua-compatible" content="ie=edge">

<!-- Bootstrap CSS -->

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

Page 11: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Getting your Web Page Bootstrap Ready

At the bottom of the page, just before the end of the body tag, add the following code to include the JQuery library

<!-- jQuery first, then Tether, then Bootstrap JS. --> <script src="node_modules/jquery/dist/jquery.min.js"></script><script src="node_modules/tether/dist/js/tether.min.js"></script> <scriptsrc="node_modules/bootstrap/dist/js/bootstrap.min.js">

</script>

Now, do a Git commit with the message "Intro. to Bootstrap".

You may push the commit to your online repository.

Page 12: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Why Responsive Design?

Users increasingly accessing websites from a variety of devices of different screen sizes

One size fits all, no longer a possibility!

Adapt to the user’s “viewport”

Build it into the core of the site

Page 13: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Mobile First Design

Mobile Computer

Mobile First

Traditional

First satisfy theMobile constraints

Page 14: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Foundation for Responsive Design

Grid system

Fluid images

Media queries

Page 15: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Media Queries

CSS technology to apply some styles based on the size of the viewport

e.g.,

@media (min-width: 992px) {

/* CSS styles customized for desktop */

}

Page 16: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Viewport<meta name="viewport" content="width=device-width,

initial-scale=1, shrink-to-fit=no">

The viewport meta tag:

Ensures that the screen width is set to the device width

and the content is rendered with this width in mind

Designing the websites to be responsive to the size of

the viewport

Bootstrap grid system

http://v4-alpha.getbootstrap.com/layout/grid/

Page 17: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap Grid

Designed to be:

Responsive

Mobile first

Fluid

Page 18: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

CSS Flexbox Layout

Simpler and flexible layout options in CSS

Can easily handle dynamic/unknown size of

content containers

Direction-agnostic layout

Page 19: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Why Flexbox for Bootstrap?

Easy vertical alignment of content within a parent element

Easy reordering of content across devices and screen resolutions with the help of media queries

Easy CSS-only equal height columns for your gridbased layouts

Page 20: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap Grid

Page 21: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap GridBootstrap makes available five classes

default targets all screen sizes from extra small to extra large,

sm for small,

md for medium,

lg for large, and

xl for extra large screen sizes

Each row in Bootstrap grid system is divided into 12 columns

Use the classes .col-*, .col-sm-*, .col-md-*, and .col-lg-* for defining

the layouts for the various screen sizes

Specify how many columns each piece of content will occupy within a

row, all adding up to 12 or a multiple thereof

Page 22: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap Grid

Page 23: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Auto-layout Columns

Page 24: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap Grid Details

Extra small<576px

Small≥576px

Medium≥768px

Large≥992px

Extra large≥1200px

Grid behaviorHorizontalat all times

Collapsed to start, horizontal above breakpoints

Max containerwidth

None (auto) 540px 720px 960px 1140px

Class prefix .col- .col-sm- .col-md- .col-lg- .col-xl-

# of columns 12

Gutter width 30px (15px on each side of a column)

Nestable Yes

Offsets Yes

Page 25: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Using Column classes

Extra Small Screens Small,

Medium, Large and Extra Large Screens

Page 26: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Using Column Push and Pull

Extra Small Screens Small,

Medium, Large and Extra Large Screens

Page 27: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Reordering Content

Extra Small Screens Small,

Medium, Large and Extra Large Screens

Page 28: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Vertical Alignment

Page 29: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Horizontal Alignment

Page 30: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Column Offset

Page 31: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Nesting Columns

Page 32: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Exercise

Responsive Design and Bootstrap Grid System

Create responsive websites using the Bootstrap grid system

Customize the CSS classes through your own additions in a separate CSS file

Page 33: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Bootstrap Grid System and Responsive Design

Media Query<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

Using a Container class<div class="container"> ...

Dividing the content into rows<div class="row"> ...

Creating a Jumbotron<header class="jumbotron"> ...

Creating a footer

Page 34: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Applying column classes within each row

Header<div class="col-12 col-sm-8"> ... </div>

<div class="col col-sm"> ... </div>

Inner<div class="col-sm-4 col-md-3"> ... </div> <div class="col-sm col-md"> ... </div>

Footer<div class="col-5 col-sm-2"> ... </div> <div class="col-6 col-sm-5"> ... </div> <div class="col col-sm-4"> ... </div> <div class="col-auto"> ... </div>

Page 35: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Push, Pull and Offset

Using Push, Pull and Offset with column layout classes<div class="col-sm-4 push-sm-8 col-md-3 push-md-9"> ... </div> <div class="col-sm pull-sm-4 col-md pull-md-3"> ... </div>

For the div containing the <ul> with the site links, update the class as follows<div class="col-5 offset-1 col-sm-2">

Save all the changes, you can do a Git commit with the message "Bootstrap Grid Part 1"

Page 36: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Using Flex Order<div class="col-sm-4 col-md-3 flex-last"> ... </div> <div class="col-sm col-md flex-first"> ... </div>

List styles<ul class="list-unstyled"> ... </ul>

Page 37: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Custom CSS class.row-header{

margin:0px auto;

padding:0px;

}

.row-content {

margin:0px auto;

padding: 50px 0px 50px 0px;

border-bottom: 1px ridge;

min-height:400px;

}

.footer{

background-color: #D1C4E9;

margin:0px auto;

padding: 20px 0px 20px 0px;

}

Page 38: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Custom CSS class

Include style.css into index.html<link href="css/styles.css" rel="stylesheet">

Add Classes<div class="row row-header"> ... </div>

<div class="row row-content"> ... </div>

<div class="row row-content"> ... </div>

<div class="row row-content"> ... </div>

<footer class="footer"> ... </footer>

Page 39: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Customize Jumbotron and the Address.jumbotron {

padding:70px 30px 70px 30px;

margin:0px auto;

background: #9575CD ;

color:floralwhite;

}

address{

font-size:80%;

margin:0px;

color:#0f0f0f;

}

Page 40: Front-End UI: Bootstrapimranihsan.com/upload/lecture/RWW1803.pdfResponsive Web Design –BootStrap Front-End UI: Bootstrap Responsive Design and Grid System. What are Front-end UI

Content

Vertically Centering the Content

In the content section, update all rows

<div class="row row-content align-items-center">

In the footer, update the third column div

<div class="col col-sm-4 align-self-center">

Horizontally Centering the Content

Update the copyright paragraph

<div class="row justify-content-center"> <div class="col-auto">