responsive styles - github pages · many css frameworks support responsive design by providing a...

28
Responsive Styles INFO 343

Upload: others

Post on 24-May-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Responsive Styles

INFO 343

Page 2: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Today's Objectives

Review basic CSS syntax

Apply conditional styles by using media queries

Create flexible layouts with the flexbox display

Introduce the use of CSS frameworks (not needed for a2)

Page 3: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

CSS Review

Page 4: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

The Box-Model

Page 5: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

CSS Displays

Page 6: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Media Queries

Page 7: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

We will practice mobile-first web design. Why mobile, and why first?

Page 8: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Mobile first web design

Page 9: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Media Queries

Allow you to apply conditional styles, depending on the screen width

Default styles should target small devices (why?)

/* Styles out here are applied by default, and should target mobile devices */

@media screen and (min-width:992px) {

/* Assign multiple styles in here for screens larger than 991px */

#element-1 {

font-size:10px;

}

.klass-1 {

font-size:20px;

}

} module-8

Page 11: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Flexbox

Page 12: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Box-sizing: border-box; module-8

Include padding and border in the size of the box!

Page 13: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Flexbox

Provides a simple syntax for distributing elements within a container

Manipulates the height, width, and alignment of immediate children

Multiple advantages, such as matching the height of elements

module-8

Page 14: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Assign the display property to flex for your container element.flex-container {

display:flex; /* Set the container display to flex */

}

Assign child elements properties to set how much space they'll occupy.flex-item {

flex-basis:25%; /* Set the amount of horizontal space to take up */

}

Flexbox: how it works

module-8

Page 15: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

The following properties will help you better control your flexbox layout

- justify-content: Horizontally distribute item in your container- align-items: Vertically distribute items in your container- flex-wrap: Wrap items onto a new line (if necessary)

Flexbox: Additional properties

module-8

Page 16: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

How can we use flexbox and media queries together?

Page 18: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

CSS Frameworks

Page 19: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

(you don't need to use one for the assignment due Tuesday)

Page 20: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Lots of CSS code that someone else wrote, that can make your website look nice

Page 21: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

We'll introduce Materialze, but feel free to use a Framework of your choice

Page 22: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Read it into your <head> section of your .html file

Some frameworks enable reactive elements by loading JavaScript files

<head>

<!-- Compiled and minified CSS -->

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/css/materialize.min.css">

<!-- Load jQuery library, a dependency for Materialize -->

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<!-- Compiled and minified JavaScript -->

<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/js/materialize.min.js"></script>

</head>

Loading a Framework

module-8

Page 23: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Assign classes that reference the .css files that you've loaded

<button class="btn">Class "BTN"</button>

<button>Without "btn"</button>

Using a Framework

module-8

Page 24: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Many CSS frameworks support responsive design by providing a grid system

In Materialze, there is a 12 column grid system, all of equal width

Use classes to specify how many columns you want an element to occupy on which screensize

The Grid

module-8

Page 26: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Assign each element multiple classes to specify the number of columns given the screensize

<!-- Container div with pre-set styles from Materialize -->

<div class="container">

<!-- A row for your grid -->

<div class="row">

<!-- An element that will take up:

- 12 columns on a small screen (<=600px),

- 6 columns on a medium screen (<=992px), and

- 4 columns on a large screen (>992px) -->

<div class="col s12 m6 l4">...</div>

</div>

</div>

Achieving Responsiveness

module-8

A lot less work than media queries!

Page 28: Responsive Styles - GitHub Pages · Many CSS frameworks support responsive design by providing a grid system In Materialze, there is a 12 column grid system, all of equal width Use

Upcoming...

By Tuesday: You should feel comfortable with module 8

Due Tuesday, 10/11 (8:30 a.m.): a2-html-css