Media Query Usage Syntax
When used inside a CSS file ?
A media query is composed of a media type and can include one or more media features that evaluate to true or false. (The mediatype is optional, if omitted, it will be set to all. However, if you use not or only, you must also specify a mediatype.) Whenever a media query is evaluated to be true, the corresponding style rules inside it will be applied.
|
|
When used outside a CSS file ?
An alternative way of using the meidia query on the html file, below are some examples:
|
|
Syntax Detail
Operand
Meaning of the not
, only
, and and
keywords:
Value | Description |
---|---|
not | This keyword inverts the meaning of an entire media query. |
only | This keyword prevents older browsers that do not support media queries from applying the specified styles. It has no effect on modern browsers. |
and | This keyword combines a media type and one or more media features. |
Media Type
Value | Description |
---|---|
all | Used for all media type devices |
print | Used for print preview mode |
screen | Used for computer screens, tablets, smart-phones etc. |
Media Feature
Value | Description |
---|---|
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) |