February 27, 2024

CSS - Using media query features

Media Query features define the style for specific characteristics of a given user agent, output device, or environment.

Media features can be either range or discrete.

Discrete features take their value from an enumerated set of possible keyword values. For example, the discrete orientation feature accepts either landscape or portrait.

@media print and (orientation: portrait) {
  colod: red;
}

Many range features can be prefixed with min- or max- to express "minimum condition" or "maximum condition" constraints. For example, this CSS will apply styles only if your browser's viewport width is equal to or narrower than 1000px:

@media (max-width: 1000px) {
  colod: blue;
}

An alternative syntax for above condition is to use ordinary mathematical comparison operators >, <, >=, or <=.

@media (width <= 1000px) {
  colod: blue;
}

@media (width <= 1000px) is the equivalent of @media (max-width: 1000px).

These are some other commonly used media features:

  • orientation: Orientation of the viewport (landscape or portrait)
  • max-height: Maximum height of the viewport
  • min-height: Minimum height of the viewport
  • height: Height of the viewport (including scrollbar)
  • max-width: Maximum width of the viewport
  • min-width: Minimum width of the viewport
  • width: Width of the viewport (including scrollbar)

Related Post(s):

1 comment: