Bo dinglesTM - -   Bright Lightbulb Graphic Ideas   - -

The Web Developer Bootcamp 2024

Colt Steele

Back to Class Page


Responsive Web Design

Flexbox & Responsive Web Design Course PDF

Media queries allow you to apply CSS styles depending on a device's media type (such as print vs. screen) or other features or characteristics such as screen resolution or orientation, aspect ratio, browser viewport width or height, user preferences such as preferring reduced motion, data usage, or transparency.


Media queries are used for the following:

  • To conditionally apply styles with the CSS @media and @import at-rules.
  • To target specific media for the <style>, <link>, <source>, and other HTML elements with the media= or sizes=" attributes.
  • To test and monitor media states using the Window.matchMedia() and EventTarget.addEventListener() methods.


To use media queries, you must fist add the following to the < head> section of your webpage:


Then in CSS you would make a statement like :

  • @media (min-width: 600px) {
    • enter styling code blocks here
  • }
which means, if a viewport size is at least 600px wide, do the formatting.


You can also combine queries, like so:

  • @media (min-width: 600px) and (max-width: 1000px) {
    • enter styling code blocks here
  • }
which means, if a viewport size is at least 600px wide, and less than 1000px wide, do the formatting.


Device Breakpoints

W3Schools Typical Device Breakpoints

Dev Facts Device Breakpoints

At this time in 2024, there are no set standards for "Typical Device Breakpoints", there are a few general observations.


  • Extra small devices (phones, 600px and down)
    @media only screen and (max-width: 600px)

  • Small devices (portrait tablets and large phones, 600px and up)
    @media only screen and (min-width: 600px)

  • Medium devices (landscape tablets, 768px and up)
    @media only screen and (min-width: 768px)

  • Large devices (laptops/desktops, 992px and up)
    @media only screen and (min-width: 992px)

  • Extra large devices (large laptops and desktops, 1200px and up)
    @media only screen and (min-width: 1200px)


From the Masyntech class:

  • Mobile devices: 480 pixels or less
  • Tablets and iPads: 481 to 768 pixels
  • Small screens and laptops: 769 to 1024 pixels
  • Desktops and large screens: 1025 to 1200 pixels
  • Extra large screens and TVs: 1201 pixels and greater



         

Change the size of the browser window to see the effect.


Media Queries

Here's the code:

HTML

  • < nav class="navbar">
    • < a href="#home">Home< /a>
    • < ul>
      • < li> < a href="#Home">Learn More< /a> < /li>
      • < li> < a href="#Home">About< /a> < /li>
      • < a href="#signup">Sign Up< /a>
    • < /ul>
    • < a href="#Home">Contact< /a>
  • < /nav>
  • < h1>Media Queries< /h1>

CSS


Back to Top