Category Archives: css (@media) Issue

css @media rules

Here is an example stylesheet that uses @media rules:

body
{
    color:#444;
    background-color:#fff;
}
@media screen, projection
{
    body { background-image:url(background.png); }
}
@media print
{
    body { color:#000; }
}
@media handheld
{
    body { color:#0f6517; }
}

Assuming that the above rules are in a CSS file that applies to all media, the following will apply:

  • For the screen and projection media types, text will be dark grey and the background will consist of a repeated image.
  • For the print media type, text will be black on white.
  • User agents that apply the handheld media type will render dark green text on a white background.
  • For all other media types, text will be dark grey on white.

This may or may not work for you, but personally I’ve found that doing this leads to less redundancy and reduces the risk of one or more media types being overlooked when I make changes to the CSS.