SlideShare a Scribd company logo
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

More Related Content

What's hot

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
Svitlana Ivanytska
 
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
 
Css Basics
Css BasicsCss Basics
Css Basics
Jay Patel
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
casestudyhelp
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
Salman Memon
 
Css
CssCss
New Elements & Features in CSS3
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3Jamshid Hashimi
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
Dave Kelly
 
CSS
CSSCSS
Css
CssCss
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
Jacob Nelson
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
KADAMBARIPUROHIT
 
HTML & CSS Masterclass
HTML & CSS MasterclassHTML & CSS Masterclass
HTML & CSS Masterclass
Bernardo Raposo
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
Ron Reiter
 
Html5 semantics
Html5 semanticsHtml5 semantics
Html5 semantics
Webtech Learning
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
Fahim Abdullah
 
Css3
Css3Css3

What's hot (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
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
CSS
CSSCSS
CSS
 
Css Basics
Css BasicsCss Basics
Css Basics
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
Css
CssCss
Css
 
New Elements & Features in CSS3
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 
CSS
CSSCSS
CSS
 
Css
CssCss
Css
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
 
HTML & CSS Masterclass
HTML & CSS MasterclassHTML & CSS Masterclass
HTML & CSS Masterclass
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Html5 semantics
Html5 semanticsHtml5 semantics
Html5 semantics
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
html5.ppt
html5.ppthtml5.ppt
html5.ppt
 
Css3
Css3Css3
Css3
 

Viewers also liked

Media queries and frameworks
Media queries and frameworksMedia queries and frameworks
Media queries and frameworks
Nicole 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 Design
Brad Frost
 
AngularJS best practices
AngularJS best practicesAngularJS best practices
AngularJS best practices
Filip Bruun Bech-Larsen
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015
Matt Raible
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
Henry Tao
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Betclic Everest Group Tech Team
 
New Features in Angular 1.5
New Features in Angular 1.5New Features in Angular 1.5
New Features in Angular 1.5
Kenichi Kanai
 
CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
Russ Weakley
 
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
Litmus
 
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
Chris Love
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Narek Mamikonyan
 

Viewers also liked (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
 

Similar to CSS3 Media Queries

CSS media types
CSS media typesCSS media types
CSS media types
Russ Weakley
 
Mediaqueries
MediaqueriesMediaqueries
Mediaqueries
Brillio
 
Web Programming
Web ProgrammingWeb Programming
Web Programming
NilaNila16
 
Print CSS
Print CSSPrint CSS
Print CSS
Russ Weakley
 
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 Design
Fawzia 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 Design
Jason 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.pptx
zainm7032
 
Team styles
Team stylesTeam styles
Team styles
nathanscott
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Tung Dang
 
New Css style
New Css styleNew Css style
New Css style
BUDNET
 
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
Andolasoft Inc
 
Web Accessibility for the 21st Century
Web Accessibility for the 21st CenturyWeb Accessibility for the 21st Century
Web Accessibility for the 21st Century
dreamwidth
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
William Myers
 
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
Patrick Lauke
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
McSoftsis
 
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
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
danpastori
 

Similar to CSS3 Media Queries (20)

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)
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 

More from Russ Weakley

Accessible chat windows
Accessible chat windowsAccessible chat windows
Accessible chat windows
Russ Weakley
 
Accessible names & descriptions
Accessible names & descriptionsAccessible names & descriptions
Accessible names & descriptions
Russ Weakley
 
A deep dive into accessible names
A deep dive into accessible namesA deep dive into accessible names
A deep dive into accessible names
Russ 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 components
Russ 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 Systems
Russ Weakley
 
Creating accessible modals and autocompletes
Creating accessible modals and autocompletesCreating accessible modals and autocompletes
Creating accessible modals and autocompletes
Russ Weakley
 
Building an accessible progressive loader
Building an accessible progressive loaderBuilding an accessible progressive loader
Building an accessible progressive loader
Russ 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 glory
Russ Weakley
 
Accessible Inline errors messages
Accessible Inline errors messagesAccessible Inline errors messages
Accessible Inline errors messages
Russ Weakley
 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and Errors
Russ 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 Libraries
Russ Weakley
 
Accessibility in pattern libraries
Accessibility in pattern librariesAccessibility in pattern libraries
Accessibility in pattern libraries
Russ Weakley
 
Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24Building an accessible auto-complete - #ID24
Building an accessible auto-complete - #ID24
Russ Weakley
 
Building an accessible auto-complete
Building an accessible auto-completeBuilding an accessible auto-complete
Building an accessible auto-complete
Russ Weakley
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labels
Russ Weakley
 
Creating an Accessible button dropdown
Creating an Accessible button dropdownCreating an Accessible button dropdown
Creating an Accessible button dropdown
Russ 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 Switch
Russ Weakley
 

More from 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
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 

Recently uploaded (20)

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 

CSS3 Media Queries

  • 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!