CSS
CSS introduction
Stylesheets
CSS syntax
Classes and ID's
CSS Comments
BG properties
Text properties
Font properties
List properties
Border properties
Margin properties
Padding properties
Outline properties
Table properties
Dim properties
Class properties
Position properties
Pseudo classes
Pseudo elements
Media types
Summary

Programming

Programming intro
Java

Markup

First webpage guide
HTML
XHTML

Browser scripting

Javascript
VBScript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

CSS media types

What if you want to display the content of a webpage differently depending on the media used? For example, if you wanted the content of a webpage to appear one way on a computer screen, but in a different way if it is printed out? With CSS "media types" you can specify a different appearance for webpages depending on where they are displayed.

This lesson focuses on:

Different media types

You can display web content on a variety of media. Each media type has a keyword associated with it that you should use to specify how content should appear on that media.

Media type Keyword Description
All all Specifies a general appearance for all media
Computer screens screen Specifies an appearance for computer screens
Printers print Specifies how content will appear on print preview and when it is printed
Handheld devices handheld Specifies how content will appear on handheld devices

The @media rule

You can use the @media rule in stylesheets to specify how content should appear on different media. To specify style rules for different media, use the @media rule followed by the keyword signifying the type of media you want to set style rules for, folowed by an opening curly brace, the style rules, and a closing curly brace.

Syntax:

@media typeOfMedia{

style rules

}

Example:

<html>
<head>
<title>Media types</title>
<style type="text/css">
<!--
@media screen{

body {font-size: 14pt;}

}

@media print{

body {font-size: 12pt;}

}
-->
</style>
</head>
<body>
Some text
</body>
</html>

In the above example, text on a webpage is specified to be 14 points in size when it is viewed on the screen, and 12 points in size when it is printed.

Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments