CSS3 Media Queries And Creating Adaptive Layouts

33
CSS3 Media Queries and Creating Adaptive Layouts BY SVITLANA IVANYTSKA
  • date post

    21-Oct-2014
  • Category

    Engineering

  • view

    210
  • download

    3

description

Brief overview about difference of adaptive and responsive web design, main principles of build responsive layout, and main component of responsive layout is media query.

Transcript of CSS3 Media Queries And Creating Adaptive Layouts

Page 1: CSS3 Media Queries And Creating Adaptive Layouts

CSS3 Media Queries and Creating Adaptive LayoutsBY SVITLANA IVANYTSKA

Page 2: CSS3 Media Queries And Creating Adaptive Layouts

“As a web developer you should target multiple (all)

devices”

Page 3: CSS3 Media Queries And Creating Adaptive Layouts

ADAPTIVE VS RESPONSIVE

Page 4: CSS3 Media Queries And Creating Adaptive Layouts

ADAPTIVE VS RESPONSIVE

Page 5: CSS3 Media Queries And Creating Adaptive Layouts

MAIN CONCEPTS OF ADAPTIVE DESIGN

progressive enhancement

mobile first

Page 6: CSS3 Media Queries And Creating Adaptive Layouts

ADAPTIVE WEB DESIGN

“Adaptive Web Design (AWD) uses predefined layouts that have been carefully constructed for a variety of screen sizes.”

Page 7: CSS3 Media Queries And Creating Adaptive Layouts

RESPONSIVE WEB DESIGN

“Responsive web design (RWD) is a web design approach aimed at crafting sites to provide an optimal viewing experience across a wide range of devices.”

Page 8: CSS3 Media Queries And Creating Adaptive Layouts

MAJOR ASPECTS

SITE SPEED

COMPLEXITY OF DEVELOPMENT

SEO

Page 9: CSS3 Media Queries And Creating Adaptive Layouts

MAIN PRINCIPLES

FLEXIBLE GRID-BASED LAYOUTS

FLEXIBLE MEDIA

MEDIA QUERIES

Page 10: CSS3 Media Queries And Creating Adaptive Layouts

FLEXIBLE LAYOUTS

relative length units(%, em)

fixed measurement units(px or in)

Page 11: CSS3 Media Queries And Creating Adaptive Layouts

FLEXIBLE GRIDtarget ÷ context = result

.container { width: 538px;}section, aside { margin: 10px;}section { float: left; width: 340px;}aside { float: right; width: 158px;}

CSS

<div class="container"> <section>...</section> <aside>...</aside></div>

HTML

section, aside { margin: 1.858736059%; /* 10px ÷ 538px = .018587361 */}section { float: left; width: 63.197026%; /* 340px ÷ 538px = .63197026 */}aside { float: right; width: 29.3680297%; /* 158px ÷ 538px = .293680297 */}

Page 12: CSS3 Media Queries And Creating Adaptive Layouts

FLEXIBLE IMAGES

Page 13: CSS3 Media Queries And Creating Adaptive Layouts

FLEXIBLE MEDIAimg, video, canvas { max-width: 100%;}

img { max-width: 100%; height: auto;}

.container{ overflow: hidden;}

Page 14: CSS3 Media Queries And Creating Adaptive Layouts

MEDIA QUERIES

“Media Queries is a CSS3 module allowing content rendering to adapt to a specific range of output devices without having to change the content itself.”

Page 15: CSS3 Media Queries And Creating Adaptive Layouts

DECLARE MEDIA QUERY

As in media types, there are three ways to invoke media-query-dependent styles:

<link rel="stylesheet" type="text/css" media="all and (color)" href="/style.css">

@import url("/style.css") all and (color);

@media all and (color) { /* one or more css rule here… */ }

First of all, as stylesheets in the link element of HTML:

In CSS stylesheets using @import rules:

And finally, using @media rules:

Page 16: CSS3 Media Queries And Creating Adaptive Layouts

SYNTAX

@media type and (expression){ ... }

screen

printer tv

projector

css codeintegration

css ruleorientation

coloraspect ratio

resolution

width/height

Page 17: CSS3 Media Queries And Creating Adaptive Layouts

MEET THE MEDIA TYPES: ALL

Description: All devices listen to this

Page 18: CSS3 Media Queries And Creating Adaptive Layouts

MEDIA TYPE: SCREEN

Description: Used primary for color computer screens and smartphones.

Page 19: CSS3 Media Queries And Creating Adaptive Layouts

MEDIA TYPE: PRINT

Description: Used for paged material and for documents viewed on screen in print preview mode.

Page 20: CSS3 Media Queries And Creating Adaptive Layouts

MEDIA TYPE: TV

Description: Used for television-type devices (low resolution, color, limited-scrollability screens, sound available)

Page 21: CSS3 Media Queries And Creating Adaptive Layouts

ADDITIONAL MEDIA TYPES

handheld projection braille embossed speech tty

Page 22: CSS3 Media Queries And Creating Adaptive Layouts

MEET THE FEATURESThe following table contains the media features listed in the latest W3C recommendation for media queries.

Feature Value Min/Max Descriptionwidth length yes Display widthheight length yes Display heightdevice-width length yes Device widthdevice-height length yes Device heightorientation portrait or landscape no Device orientationaspect-ratio ratio (w/h) yes Ratio of width to heightdevice-aspect-ratio ratio (w/h) yes Ratio of device-width to device-heightcolor integer yes Number of bits per color component

color-index integer yes Number of entries in the output device’s color lookup table

monochrome integer yes Number of bits per pixel in the monochrome frame buffer

resolution resolution yes Density of pixels of output device, (integer followed by dpi or dpcm)

Page 23: CSS3 Media Queries And Creating Adaptive Layouts

MEDIA FEATURE: WIDTH/HEIGHT

Value: <length>Media: all, but not speech (visual, tactile)Accepts min/max prefixes: yes

/* width */@media screen and (max-width: 600px) { ... }@media screen and (min-width:200px) and (max-width:400px) { ... }

/* height */@media screen and (max-height:768px) { ... }@media (min-height:500px) and (max-height:580px) { ... }

Page 24: CSS3 Media Queries And Creating Adaptive Layouts

MEDIA FEATURE: ORIENTATION

Value: <length>Media: handheld, print, projection, screen, tty, tv

@media screen and (orientation: portrait) { … }

@media screen and (orientation: landscape) { … }

Page 25: CSS3 Media Queries And Creating Adaptive Layouts

MEDIA FEATURE: RESOLUTION

Value: <resolution>Media: handheld, print, projection, screen, tvAccepts min/max prefixes: yes

/* apply to devices with at least 300 dots per inch of resolution: */@media print and (min-resolution: 300dpi) { ... }

/* to replace the old (min-device-pixel-ratio: 2) syntax: */@media screen and (min-resolution: 2dppx) { ... }

Page 26: CSS3 Media Queries And Creating Adaptive Layouts

LOGICAL OPERATORS

Using logical operators in media queries such as: AND

NOT

ONLY

OR (COMMA-SEPARATED LISTS)

@media all and (color) { ... }

@media not screen and (color) { ... }

@media only screen and (orientation: portrait) { ... }

@media all and (orientation: landscape), all and (min-width: 480px) { ... }

Page 27: CSS3 Media Queries And Creating Adaptive Layouts

WEB BROWSER SUPPORT

Page 28: CSS3 Media Queries And Creating Adaptive Layouts

SUPPORT OLD BROWSERS

css3-mediaqueries.js

make CSS3 Media Queries work in all browsers (JavaScript library) starts from:

IE 5+ Firefox 1+ Safari 2

Page 29: CSS3 Media Queries And Creating Adaptive Layouts

EXAMPLE: NON-RESPONSIVE

https://www.apple.com/http://www.amazon.com/ https://www.usps.com/

Page 30: CSS3 Media Queries And Creating Adaptive Layouts

EXAMPLE: RESPONSIVE

http://mediaqueri.es/

Page 31: CSS3 Media Queries And Creating Adaptive Layouts

CSS3 MEDIA QUERIES ARE HERE TODAY!

A SINGLE WEBSITE

A SINGLE URL

EASY SEO AND MARKETING

LOW COST

Page 32: CSS3 Media Queries And Creating Adaptive Layouts

RESOURCES Aaron Gustafson, Adaptive Web Design: Crafting Rich Experiences with

Progressive Enhancement. — Easy Readers, 2011. Ben Frain, Responsive Web Design with HTML5 and CSS3. — Packt

Publishing Ltd, 2012. Ethan Marcotte, Responsive Web Design. — A Book Apart, 2011.  Luke Wroblewski, Mobile First. — A Book Apart, 2011.

Page 33: CSS3 Media Queries And Creating Adaptive Layouts