Loading Please Wait...

Logo Lynxsia IT Solutions

CSS Media Queries

CSS Media Queries

Media queries allow you to apply CSS styles depending on a device's general type (such as print vs. screen) or other characteristics such as screen resolution or browser viewport width.

Syntax
					 
        
          @media not|only mediatype and (expressions) {
            CSS-Code;
          }
        
      
Types of Media

all: Used for all media type devices.

print: Used for printers.

screen: Used for computer screens, tablets, smart phones, smart watches, laptop, etc.

speech: Used for screen readers that "reads" the page out loud.

Targeting Media Types

Media types define the broad category of device for which the media query applies: all, print, screen. The type is optional (assumed to be all) except when using the not or only logical operators.

					 
        
          /* printers */
          @media print {
            /* … */
          }

          /* screens */
          @media screen {
            /* … */
          }

          /* screen readers */
          @media speech {
            /* … */
          }

          /* all */
          @media all {
            /* … */
          }

          /* multiple */
          @media screen, print{
            /* … */
          }
        
      
Targeting Media Features

Media features describe a specific characteristic of the user agent, output device, or environment

hover, width (min or max), pointer, color, grid, height, etc.

					 
        
          @media (hover: hover) {
            /* … */
          }

          @media (color) {
            /* … */
          }

          @media (min-width: 200px) {
            /* … */
          }
        
      
Targeting Multiple Types And Features
					 
        
          @media (min-width: 30em) and (orientation: landscape) {
            /* … */
          }

          @media screen and (min-width: 30em) and (orientation: landscape) {
            /* … */
          }

          @media (min-height: 680px), screen and (orientation: portrait) {
            /* … */
          }
        
      
Inverting Media Queries

The not keyword inverts the meaning of an entire media query. It will only negate the specific media query it is applied to.

					 
        
          @media not all and (monochrome) {
            /* … */
          }

          @media not (all and (monochrome)) {
            /* … */
          }

          @media not screen and (color), print and (color) {
            /* … */
          }
        
      
Improving Media Queries
					 
        
          @media (min-width: 30em) and (max-width: 50em) {
            /* … */
          }

          /* The above query can be written as */
          @media (30em <= width <= 50em) {
            /* … */
          }
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved