SlideShare uma empresa Scribd logo
1 de 91
Baixar para ler offline
CSS3
MEDIA QUERIES
Why should
you care about
media queries?
Media queries are one of the
most exciting aspects about
        CSS today.
Media queries will allow us to
  change our layouts to suit the
exact need of different devices
 - without changing the content.
For example, we will be able to
move away from “one-size-fits-
 all” solutions such as liquid,
elastic and fixed width layouts.
Let’s take a standard
3 column 1000px wide layout…
Imagine if it could become a
2 column 800px wide if the user
    has a narrower browser
           window…
…or a single column 400px
 wide layout if the user has a
mobile device or a very narrow
      browser window…
And all done with CSS alone - no
          JavaScript…
This is just one quick example
  of how media queries can
    help us deliver CSS in
   new and exciting ways
But… before we talk about
media queries, we need to do a
quick overview of media types.
So, what are
media types?
CSS can be used to specify
how a document is presented
    in different media.
There are ten media types
    defined in CSS 2.1
all   suitable for all devices
     aural    for speech synthesizers
    braille   for Braille tactile feedback devices
embossed      for paged Braille printers
 handheld     for handheld devices
     print    for print material
projection    for projected presentations
   screen     for color computer screens
        tty   for teletypes and terminals
         tv   for television type devices
There are five methods that can
   be used to specify media
        for style sheets.
Method 1:
<link> within HTML
You can use a <link> element in
the head of your HTML document
 to specify the target media of an
       external style sheet.


  <link rel="stylesheet"
  href="a.css" type="text/css"
  media=”screen" />
Method 2:
<?xml stylesheet>
   within XML
You can use <?xml-stylesheet ?>
in the head of your XML document
  to specify the target media of an
        external style sheet.


  <?xml-stylesheet
  media="screen" rel="stylesheet"
  href="example.css" ?>
Method 3:
@import within
   HTML
You can use @import in the head
if your HTML document to specify
   the target media of an external
             style sheet.


  <style type="text/css"
  media="screen">
  @import "a.css";</style>
Warning:
              @import should be avoided as it
                can cause issues in some
               versions of Internet Explorer.




http://www.stevesouders.com/blog/2009/04/09/dont-use-import/
Method 4:
@import within CSS
You can specify the target medium
 within a CSS file using @import




  @import url("a.css") screen;
Media-types within @import
rules are not supported by IE5,
IE6 or IE7. The rule is ignored.
Method 5:
@media within CSS
You can specify the target medium
 within a CSS file using @media




  @media screen
  {
      body { color: blue; }
  }
Why should we care
 about these five
    methods?
Because you can use these five
methods to define not only media
   types, but media queries
Let’s talk
media queries
Media queries are a CSS3
extension to media types that gives
 us more control over rendering
     across different devices.


   <link rel="stylesheet"
   type="text/css" href="a.css"
   media="screen and (color)">
A media query is a logical
 expression that is either
      true or false.
The CSS associated with the
media query expression is only
  applied to the device if the
     expression is true.
Media query
  syntax
A media query generally consists of
  a media type and zero or more
          expressions.


<link rel="stylesheet"
type="text/css" href="a.css"
media=”screen and (color)">

      Media type   Expression
An expression consists of zero or
   more keywords and a media
             feature.


<link rel="stylesheet"
type="text/css" href="a.css"
media=”screen and (color)">

          Keyword   Media feature
Media features are placed within
            brackets.



<link rel="stylesheet"
type="text/css" href="a.css"
media=”screen and (color)">

                 Media feature
A media feature can be used
  without a media type or keyword.
The media type is assumed to be “all”.


<link rel="stylesheet"
type="text/css" href="a.css"
media=”(color)">

      Media feature
Most media features accept
“min-” or “max-” prefixes.



<link rel="stylesheet"
type="text/css" href="a.css"
media="screen and
(min-height: 20em)">
Media features can often be used
        without a value.


  <link rel="stylesheet"
  type="text/css" href="a.css"
  media="screen and (color)">
Media features only accept single
values: one keyword, one number,
 or a number with a unit identifier.

     Except aspect-ratio and device-aspect-ration which require two numbers




   (orientation: portrait)
   (min-width: 20em)
   (min-color: 2)
   (device-aspect-ratio: 16/9)
The full media
 feature list
Feature               Value                             min/max
aspect-ratio          ratio (integer/integer)           yes
color                 integer                           yes
color-index           integer                           yes
device-aspect-ratio   ratio (integer/integer)           yes
device-height         length                            yes
device-width          length                            yes
grid                  integer                           no
height                length                            yes
monochrome            integer                           yes
orientation           keyword (portrait/landscape)      no
resolution            resolution (dpi)                  yes
scan                  keyword (progressive/interlace)   no
width                 length                            yes
A simple example
The CSS file in this example
    should be applied to screen
    devices that are capable of
        representing color.

<link rel="stylesheet"
type="text/css" href="a.css"
media="screen and (color)">
This same media enquiry could be
  used with @import via HTML.




<style type="text/css"
media="screen and (color) ">
@import "a.css";</style>
It could be used with
        @import via CSS.




@import url("a.css")
screen and (color);
Or using @media via CSS.




@media screen and (color)
{
    body { color: blue; }
}
Multiple expressions
You can use multiple
expressions in a media query if
  you join them with the “and”
            keyword.
The CSS file in this example will be
 applied by hand-held devices, but
   only if the viewport width is at
        > 20em and < 40em.

<link rel="stylesheet"
type="text/css" href="a.css"
media="handheld and (min-width:20em)
and (max-width:40em)">
Comma separated
You can also use multiple,
comma-separated media queries.
  The comma acts like an “or”
           keyword.
The CSS file in this example will be
   applied to screen with color or
   handheld devices with color.


<link rel="stylesheet"
type="text/css" href="a.css"
media="screen and (color),
handheld and (color)">
Using the “not”
   keyword
You can use the not keyword in a
media query if you want your CSS
to be ignored by a specific device.
The CSS file in this example will be
 applied to all devices except those
         with color screens.


<link rel="stylesheet"
type="text/css" href="a.css"
media="not screen and (color)">
Using the “only”
  expression
The CSS file in this example will be
   applied only to all devices with
           color screens.


<link rel="stylesheet"
type="text/css" href="a.css"
media="only screen and (color)">
Support for
media queries
Browser support for media queries:

    IE8                            no
    Firefox 3.6                    yes
    Safari 4                       yes
    Opera 10                       yes
    Chrome 5                       yes

   * Based on basic testing only
What do other
browsers see?
Browsers that do not support
     media queries should still
     support the media type.


<link rel="stylesheet"
type="text/css" href="a.css"
media="screen and (color)">
The “only” keyword is sometimes
   used to hide CSS from devices
 that do not support media queries,
    but may read the media type.

<link rel="stylesheet"
type="text/css" href="a.css"
media="only screen and (color)">
Targeting the
   iPhone
The iPhone does not support
   handheld media type. Apple
recommends targeting the iPhone
     using media queries.
This rule will be applied by the
   iPhone which has a maximum
   device width (screen width) of
                480px.

<link rel="stylesheet"
type="text/css" href="a.css"
media="only screen and
(max-device-width: 480px)" >
Using media
  queries to
control layouts
So, how could we use media
 queries to change a page layout
so that it can appear wide, medium
 or narrow depending on the width
            of the screen?
Here is a quick step
 by step example
Step 1:
    Add a link to your style sheet




<link rel="stylesheet"
type="text/css" href=”master.css"
media="screen" >
Step 2:
Add your “wide page layout” CSS
    rules into your CSS file
Step 3:
  Add a @media rule with a media
             query


@media screen and (max-width:999px)
{
    /* add your rules here */
}
Step 4:
 Add your “medium page layout”
CSS rules inside this @media rule.
Step 5:
 Add a second @media rule with a
          media query

@media screen and (max-width:480px)
{
    /* add your rules here */
}
Step 6:
 Add your “narrow page layout”
CSS rules inside this new @media
               rule.
Your CSS file should be structured
      something like this:

  Wide page layout CSS rules

@media screen and (max-width:999px)
{
   Medium page layout CSS rules
}

@media screen and (max-width:480px)
{
   Narrow page layout CSS rules
}
A note on the CSS
Devices wider than 1000px will see
the “wide page layout” CSS only.
Devices narrower than 1000px will
see the “wide page layout” CSS
 AND the “medium page layout”
             CSS.
Devices narrower than 480px will
  see the “wide page layout”,
  “medium page layout” and
  “narrow page layout” CSS.
What does this
   mean?
This means that rules written inside
  each @media statements must
   override the previous rules.
A quick
 recap
I believe that as media queries
become supported, we will see a
 radical change in the way we
develop websites in the future.
Now is a good time to get
  your head around these
powerful CSS3 expressions
so that you are ready when
     the time comes!
We’re done

Mais conteúdo relacionado

Mais procurados

Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3Doris Chen
 
Media queries A to Z
Media queries A to ZMedia queries A to Z
Media queries A to ZShameem Reza
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSSMario Hernandez
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout Rachel Andrew
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpcasestudyhelp
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Chris Poteet
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginnersSingsys Pte Ltd
 
Responsive web designing ppt(1)
Responsive web designing ppt(1)Responsive web designing ppt(1)
Responsive web designing ppt(1)admecindia1
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3Lanh Le
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overviewJacob Nelson
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS Dave Kelly
 

Mais procurados (20)

Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
Media queries A to Z
Media queries A to ZMedia queries A to Z
Media queries A to Z
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginners
 
CSS for Beginners
CSS for BeginnersCSS for Beginners
CSS for Beginners
 
Responsive web designing ppt(1)
Responsive web designing ppt(1)Responsive web designing ppt(1)
Responsive web designing ppt(1)
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
 
Javascript
JavascriptJavascript
Javascript
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Advanced Cascading Style Sheets
Advanced Cascading Style SheetsAdvanced Cascading Style Sheets
Advanced Cascading Style Sheets
 
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
 
Css position
Css positionCss position
Css position
 
Web Standards
Web StandardsWeb Standards
Web Standards
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 
Java script
Java scriptJava script
Java script
 

Destaque

Media queries and frameworks
Media queries and frameworksMedia queries and frameworks
Media queries and frameworksNicole Ryan
 
Beyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBeyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBrad Frost
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015Matt Raible
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practicesHenry Tao
 
New Features in Angular 1.5
New Features in Angular 1.5New Features in Angular 1.5
New Features in Angular 1.5Kenichi Kanai
 
Mobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesMobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesLitmus
 
Css best practices style guide and tips
Css best practices style guide and tipsCss best practices style guide and tips
Css best practices style guide and tipsChris Love
 

Destaque (11)

Media queries and frameworks
Media queries and frameworksMedia queries and frameworks
Media queries and frameworks
 
Beyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web DesignBeyond Media Queries: Anatomy of an Adaptive Web Design
Beyond Media Queries: Anatomy of an Adaptive Web Design
 
AngularJS best practices
AngularJS best practicesAngularJS best practices
AngularJS best practices
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
New Features in Angular 1.5
New Features in Angular 1.5New Features in Angular 1.5
New Features in Angular 1.5
 
CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
 
Mobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best PracticesMobile Email Design, Strategies, Workflow and Best Practices
Mobile Email Design, Strategies, Workflow and Best Practices
 
Css best practices style guide and tips
Css best practices style guide and tipsCss best practices style guide and tips
Css best practices style guide and tips
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 

Semelhante a CSS3 Media Queries: Why and How to Use Them

CSS3 Media Queries And Creating Adaptive Layouts
CSS3 Media Queries And Creating Adaptive LayoutsCSS3 Media Queries And Creating Adaptive Layouts
CSS3 Media Queries And Creating Adaptive LayoutsSvitlana Ivanytska
 
Mediaqueries
MediaqueriesMediaqueries
MediaqueriesBrillio
 
Web Programming
Web ProgrammingWeb Programming
Web ProgrammingNilaNila16
 
Introduction to Responsive Web Design
Introduction to Responsive Web DesignIntroduction to Responsive Web Design
Introduction to Responsive Web DesignShawn Calvert
 
HTML5, CSS3 & Responsive Design
HTML5, CSS3 & Responsive DesignHTML5, CSS3 & Responsive Design
HTML5, CSS3 & Responsive DesignFawzia Essa
 
Meta layout: a closer look at media queries
Meta layout: a closer look at media queriesMeta layout: a closer look at media queries
Meta layout: a closer look at media queriesStephen Hay
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignJason Harwig
 
Lect-4-Responsive-Web-06032024-082044am.pptx
Lect-4-Responsive-Web-06032024-082044am.pptxLect-4-Responsive-Web-06032024-082044am.pptx
Lect-4-Responsive-Web-06032024-082044am.pptxzainm7032
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignTung Dang
 
New Css style
New Css styleNew Css style
New Css styleBUDNET
 
Organize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksOrganize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksAndolasoft Inc
 
Web Accessibility for the 21st Century
Web Accessibility for the 21st CenturyWeb Accessibility for the 21st Century
Web Accessibility for the 21st Centurydreamwidth
 
Adaptive layouts - standards>next Manchester 23.03.2011
Adaptive layouts - standards>next Manchester 23.03.2011Adaptive layouts - standards>next Manchester 23.03.2011
Adaptive layouts - standards>next Manchester 23.03.2011Patrick Lauke
 
GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1Heather Rock
 
Responsive Web Design & APEX Theme 25 (OGh APEX World 2014)
Responsive Web Design & APEX Theme 25 (OGh APEX World 2014)Responsive Web Design & APEX Theme 25 (OGh APEX World 2014)
Responsive Web Design & APEX Theme 25 (OGh APEX World 2014)Christian Rokitta
 

Semelhante a CSS3 Media Queries: Why and How to Use Them (20)

CSS3 Media Queries And Creating Adaptive Layouts
CSS3 Media Queries And Creating Adaptive LayoutsCSS3 Media Queries And Creating Adaptive Layouts
CSS3 Media Queries And Creating Adaptive Layouts
 
CSS media types
CSS media typesCSS media types
CSS media types
 
Mediaqueries
MediaqueriesMediaqueries
Mediaqueries
 
Web Programming
Web ProgrammingWeb Programming
Web Programming
 
Print CSS
Print CSSPrint CSS
Print CSS
 
Introduction to Responsive Web Design
Introduction to Responsive Web DesignIntroduction to Responsive Web Design
Introduction to Responsive Web Design
 
HTML5, CSS3 & Responsive Design
HTML5, CSS3 & Responsive DesignHTML5, CSS3 & Responsive Design
HTML5, CSS3 & Responsive Design
 
Meta layout: a closer look at media queries
Meta layout: a closer look at media queriesMeta layout: a closer look at media queries
Meta layout: a closer look at media queries
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Lect-4-Responsive-Web-06032024-082044am.pptx
Lect-4-Responsive-Web-06032024-082044am.pptxLect-4-Responsive-Web-06032024-082044am.pptx
Lect-4-Responsive-Web-06032024-082044am.pptx
 
Team styles
Team stylesTeam styles
Team styles
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
New Css style
New Css styleNew Css style
New Css style
 
Organize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksOrganize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS Tricks
 
Web Accessibility for the 21st Century
Web Accessibility for the 21st CenturyWeb Accessibility for the 21st Century
Web Accessibility for the 21st Century
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Adaptive layouts - standards>next Manchester 23.03.2011
Adaptive layouts - standards>next Manchester 23.03.2011Adaptive layouts - standards>next Manchester 23.03.2011
Adaptive layouts - standards>next Manchester 23.03.2011
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
 
GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1
 
Responsive Web Design & APEX Theme 25 (OGh APEX World 2014)
Responsive Web Design & APEX Theme 25 (OGh APEX World 2014)Responsive Web Design & APEX Theme 25 (OGh APEX World 2014)
Responsive Web Design & APEX Theme 25 (OGh APEX World 2014)
 

Mais de Russ Weakley

Accessible chat windows
Accessible chat windowsAccessible chat windows
Accessible chat windowsRuss Weakley
 
Accessible names & descriptions
Accessible names & descriptionsAccessible names & descriptions
Accessible names & descriptionsRuss Weakley
 
A deep dive into accessible names
A deep dive into accessible namesA deep dive into accessible names
A deep dive into accessible namesRuss Weakley
 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?Russ Weakley
 
How to build accessible UI components
How to build accessible UI componentsHow to build accessible UI components
How to build accessible UI componentsRuss Weakley
 
What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?Russ Weakley
 
Accessible states in Design Systems
Accessible states in Design SystemsAccessible states in Design Systems
Accessible states in Design SystemsRuss Weakley
 
Creating accessible modals and autocompletes
Creating accessible modals and autocompletesCreating accessible modals and autocompletes
Creating accessible modals and autocompletesRuss Weakley
 
Building an accessible progressive loader
Building an accessible progressive loaderBuilding an accessible progressive loader
Building an accessible progressive loaderRuss Weakley
 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryRuss Weakley
 
Accessible Inline errors messages
Accessible Inline errors messagesAccessible Inline errors messages
Accessible Inline errors messagesRuss Weakley
 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and ErrorsRuss Weakley
 
What is accessibility?
What is accessibility?What is accessibility?
What is accessibility?Russ Weakley
 
Accessibility in Pattern Libraries
Accessibility in Pattern LibrariesAccessibility in Pattern Libraries
Accessibility in Pattern LibrariesRuss Weakley
 
Accessibility in pattern libraries
Accessibility in pattern librariesAccessibility in pattern libraries
Accessibility in pattern librariesRuss Weakley
 
Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Russ Weakley
 
Building an accessible auto-complete
Building an accessible auto-completeBuilding an accessible auto-complete
Building an accessible auto-completeRuss Weakley
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labelsRuss Weakley
 
Creating an Accessible button dropdown
Creating an Accessible button dropdownCreating an Accessible button dropdown
Creating an Accessible button dropdownRuss Weakley
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchRuss Weakley
 

Mais de Russ Weakley (20)

Accessible chat windows
Accessible chat windowsAccessible chat windows
Accessible chat windows
 
Accessible names & descriptions
Accessible names & descriptionsAccessible names & descriptions
Accessible names & descriptions
 
A deep dive into accessible names
A deep dive into accessible namesA deep dive into accessible names
A deep dive into accessible names
 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?
 
How to build accessible UI components
How to build accessible UI componentsHow to build accessible UI components
How to build accessible UI components
 
What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?What is WCAG 2 and why should we care?
What is WCAG 2 and why should we care?
 
Accessible states in Design Systems
Accessible states in Design SystemsAccessible states in Design Systems
Accessible states in Design Systems
 
Creating accessible modals and autocompletes
Creating accessible modals and autocompletesCreating accessible modals and autocompletes
Creating accessible modals and autocompletes
 
Building an accessible progressive loader
Building an accessible progressive loaderBuilding an accessible progressive loader
Building an accessible progressive loader
 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and glory
 
Accessible Inline errors messages
Accessible Inline errors messagesAccessible Inline errors messages
Accessible Inline errors messages
 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and Errors
 
What is accessibility?
What is accessibility?What is accessibility?
What is accessibility?
 
Accessibility in Pattern Libraries
Accessibility in Pattern LibrariesAccessibility in Pattern Libraries
Accessibility in Pattern Libraries
 
Accessibility in pattern libraries
Accessibility in pattern librariesAccessibility in pattern libraries
Accessibility in pattern libraries
 
Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24
 
Building an accessible auto-complete
Building an accessible auto-completeBuilding an accessible auto-complete
Building an accessible auto-complete
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labels
 
Creating an Accessible button dropdown
Creating an Accessible button dropdownCreating an Accessible button dropdown
Creating an Accessible button dropdown
 
Creating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off SwitchCreating a Simple, Accessible On/Off Switch
Creating a Simple, Accessible On/Off Switch
 

Último

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

CSS3 Media Queries: Why and How to Use Them

  • 2. Why should you care about media queries?
  • 3. Media queries are one of the most exciting aspects about CSS today.
  • 4. Media queries will allow us to change our layouts to suit the exact need of different devices - without changing the content.
  • 5. For example, we will be able to move away from “one-size-fits- all” solutions such as liquid, elastic and fixed width layouts.
  • 6. Let’s take a standard 3 column 1000px wide layout…
  • 7.
  • 8. Imagine if it could become a 2 column 800px wide if the user has a narrower browser window…
  • 9.
  • 10. …or a single column 400px wide layout if the user has a mobile device or a very narrow browser window…
  • 11.
  • 12. And all done with CSS alone - no JavaScript…
  • 13. This is just one quick example of how media queries can help us deliver CSS in new and exciting ways
  • 14. But… before we talk about media queries, we need to do a quick overview of media types.
  • 16. CSS can be used to specify how a document is presented in different media.
  • 17. There are ten media types defined in CSS 2.1
  • 18. all suitable for all devices aural for speech synthesizers braille for Braille tactile feedback devices embossed for paged Braille printers handheld for handheld devices print for print material projection for projected presentations screen for color computer screens tty for teletypes and terminals tv for television type devices
  • 19. There are five methods that can be used to specify media for style sheets.
  • 21. You can use a <link> element in the head of your HTML document to specify the target media of an external style sheet. <link rel="stylesheet" href="a.css" type="text/css" media=”screen" />
  • 23. You can use <?xml-stylesheet ?> in the head of your XML document to specify the target media of an external style sheet. <?xml-stylesheet media="screen" rel="stylesheet" href="example.css" ?>
  • 25. You can use @import in the head if your HTML document to specify the target media of an external style sheet. <style type="text/css" media="screen"> @import "a.css";</style>
  • 26. Warning: @import should be avoided as it can cause issues in some versions of Internet Explorer. http://www.stevesouders.com/blog/2009/04/09/dont-use-import/
  • 28. You can specify the target medium within a CSS file using @import @import url("a.css") screen;
  • 29. Media-types within @import rules are not supported by IE5, IE6 or IE7. The rule is ignored.
  • 31. You can specify the target medium within a CSS file using @media @media screen { body { color: blue; } }
  • 32. Why should we care about these five methods?
  • 33. Because you can use these five methods to define not only media types, but media queries
  • 35. Media queries are a CSS3 extension to media types that gives us more control over rendering across different devices. <link rel="stylesheet" type="text/css" href="a.css" media="screen and (color)">
  • 36. A media query is a logical expression that is either true or false.
  • 37. The CSS associated with the media query expression is only applied to the device if the expression is true.
  • 38. Media query syntax
  • 39. A media query generally consists of a media type and zero or more expressions. <link rel="stylesheet" type="text/css" href="a.css" media=”screen and (color)"> Media type Expression
  • 40. An expression consists of zero or more keywords and a media feature. <link rel="stylesheet" type="text/css" href="a.css" media=”screen and (color)"> Keyword Media feature
  • 41. Media features are placed within brackets. <link rel="stylesheet" type="text/css" href="a.css" media=”screen and (color)"> Media feature
  • 42. A media feature can be used without a media type or keyword. The media type is assumed to be “all”. <link rel="stylesheet" type="text/css" href="a.css" media=”(color)"> Media feature
  • 43. Most media features accept “min-” or “max-” prefixes. <link rel="stylesheet" type="text/css" href="a.css" media="screen and (min-height: 20em)">
  • 44. Media features can often be used without a value. <link rel="stylesheet" type="text/css" href="a.css" media="screen and (color)">
  • 45. Media features only accept single values: one keyword, one number, or a number with a unit identifier. Except aspect-ratio and device-aspect-ration which require two numbers (orientation: portrait) (min-width: 20em) (min-color: 2) (device-aspect-ratio: 16/9)
  • 46. The full media feature list
  • 47. Feature Value min/max aspect-ratio ratio (integer/integer) yes color integer yes color-index integer yes device-aspect-ratio ratio (integer/integer) yes device-height length yes device-width length yes grid integer no height length yes monochrome integer yes orientation keyword (portrait/landscape) no resolution resolution (dpi) yes scan keyword (progressive/interlace) no width length yes
  • 49. The CSS file in this example should be applied to screen devices that are capable of representing color. <link rel="stylesheet" type="text/css" href="a.css" media="screen and (color)">
  • 50. This same media enquiry could be used with @import via HTML. <style type="text/css" media="screen and (color) "> @import "a.css";</style>
  • 51. It could be used with @import via CSS. @import url("a.css") screen and (color);
  • 52. Or using @media via CSS. @media screen and (color) { body { color: blue; } }
  • 54. You can use multiple expressions in a media query if you join them with the “and” keyword.
  • 55. The CSS file in this example will be applied by hand-held devices, but only if the viewport width is at > 20em and < 40em. <link rel="stylesheet" type="text/css" href="a.css" media="handheld and (min-width:20em) and (max-width:40em)">
  • 57. You can also use multiple, comma-separated media queries. The comma acts like an “or” keyword.
  • 58. The CSS file in this example will be applied to screen with color or handheld devices with color. <link rel="stylesheet" type="text/css" href="a.css" media="screen and (color), handheld and (color)">
  • 60. You can use the not keyword in a media query if you want your CSS to be ignored by a specific device.
  • 61. The CSS file in this example will be applied to all devices except those with color screens. <link rel="stylesheet" type="text/css" href="a.css" media="not screen and (color)">
  • 62. Using the “only” expression
  • 63. The CSS file in this example will be applied only to all devices with color screens. <link rel="stylesheet" type="text/css" href="a.css" media="only screen and (color)">
  • 65. Browser support for media queries: IE8 no Firefox 3.6 yes Safari 4 yes Opera 10 yes Chrome 5 yes * Based on basic testing only
  • 67. Browsers that do not support media queries should still support the media type. <link rel="stylesheet" type="text/css" href="a.css" media="screen and (color)">
  • 68. The “only” keyword is sometimes used to hide CSS from devices that do not support media queries, but may read the media type. <link rel="stylesheet" type="text/css" href="a.css" media="only screen and (color)">
  • 69. Targeting the iPhone
  • 70. The iPhone does not support handheld media type. Apple recommends targeting the iPhone using media queries.
  • 71. This rule will be applied by the iPhone which has a maximum device width (screen width) of 480px. <link rel="stylesheet" type="text/css" href="a.css" media="only screen and (max-device-width: 480px)" >
  • 72. Using media queries to control layouts
  • 73. So, how could we use media queries to change a page layout so that it can appear wide, medium or narrow depending on the width of the screen?
  • 74. Here is a quick step by step example
  • 75. Step 1: Add a link to your style sheet <link rel="stylesheet" type="text/css" href=”master.css" media="screen" >
  • 76. Step 2: Add your “wide page layout” CSS rules into your CSS file
  • 77. Step 3: Add a @media rule with a media query @media screen and (max-width:999px) { /* add your rules here */ }
  • 78. Step 4: Add your “medium page layout” CSS rules inside this @media rule.
  • 79. Step 5: Add a second @media rule with a media query @media screen and (max-width:480px) { /* add your rules here */ }
  • 80. Step 6: Add your “narrow page layout” CSS rules inside this new @media rule.
  • 81. Your CSS file should be structured something like this: Wide page layout CSS rules @media screen and (max-width:999px) { Medium page layout CSS rules } @media screen and (max-width:480px) { Narrow page layout CSS rules }
  • 82. A note on the CSS
  • 83. Devices wider than 1000px will see the “wide page layout” CSS only.
  • 84. Devices narrower than 1000px will see the “wide page layout” CSS AND the “medium page layout” CSS.
  • 85. Devices narrower than 480px will see the “wide page layout”, “medium page layout” and “narrow page layout” CSS.
  • 86. What does this mean?
  • 87. This means that rules written inside each @media statements must override the previous rules.
  • 89. I believe that as media queries become supported, we will see a radical change in the way we develop websites in the future.
  • 90. Now is a good time to get your head around these powerful CSS3 expressions so that you are ready when the time comes!