Recently, In a test project I was facing a strange problem.
The webpage layout was supposed to be as follows :
The layout was supposed to cover the entire browser real estate.. and should be resizable... so no hard coded heights or widths...
I wanted to render it using a HTML table approach instead of the standard Div approach.
The first hurdle was that the Height attribute of the HTML Table isn't strictly followed during rendering in the browsers, even though the Width attribute works just fine. This was due to the fact that for the height attribute the browsers also depend on the containers height. So the oft repeated suggstion is to use a style to spread the height and weight of the 2 outermost containers of a page, i.e., the HTML and the BODY.
So I added the following style to my stylesheet:
I noticed that webpages, both aspx and plain htmls, works fine with this code..
But the moment I modify it to be used in a masterpage, all the row height formatting goes for a toss..
Teletypes and similar media using a fixed-pitch character grid
tv
Television type devices (low resolution, limited scroll ability)
Values
Value
Description
width
Specifies the width of the targeted display area.
"min-" and "max-" prefixes can be used.
Example: media="screen and (min-width:500px)"
height
Specifies the height of the targeted display area.
"min-" and
"max-" prefixes can be used.
Example: media="screen and (max-height:700px)"
device-width
Specifies the width of the target display/paper.
"min-" and "max-" prefixes can be used.
Example: media="screen and (device-width:500px)"
device-height
Specifies the height of the target display/paper.
"min-" and "max-" prefixes can be used.
Example: media="screen and (device-height:500px)"
orientation
Specifies the orientation of the target display/paper.
Possible values: "portrait" or "landscape"
Example: media="all and (orientation: landscape)"
aspect-ratio
Specifies the width/height ratio of the targeted display area.
"min-" and "max-" prefixes can be used.
Example: media="screen and (aspect-ratio:16/9)"
device-aspect-ratio
Specifies the device-width/device-height ratio of the target
display/paper.
"min-" and "max-" prefixes can be used.
Example: media="screen and (aspect-ratio:16/9)"
color
Specifies the bits per color of target display.
"min-" and "max-" prefixes can be used.
Example: media="screen and (color:3)"
color-index
Specifies the number of colors the target display can handle.
"min-" and "max-" prefixes can be used.
Example: media="screen and (min-color-index:256)"
monochrome
Specifies the bits per pixel in a monochrome frame buffer.
"min-" and "max-" prefixes can be used.
Example: media="screen and (monochrome:2)"
resolution
Specifies the pixel density (dpi or dpcm) of the target display/paper.
"min-" and "max-" prefixes can be used.
Example: media="print and (resolution:300dpi)"
scan
Specifies scanning method of a tv display.
Possible values are "progressive" and "interlace".
Example: media="tv and (scan:interlace)"
grid
Specifies if the output device is grid or bitmap.
Possible values are "1" for grid, and "0" otherwise.
Example: media="handheld and (grid:1)"
One of the most important features of style sheets is that they
specify how a document is to be presented on different media: on the
screen, on paper, with a speech synthesizer, with a braille device,
etc.
Certain CSS properties are only designed for certain media (e.g.,
the 'page-break-before' property
only applies to paged media). On occasion, however, style sheets for
different media types may share a property, but require different
values for that property. For example, the 'font-size' property is useful both
for screen and print media. The two media types are different enough
to require different values for the common property; a document will
typically need a larger font on a computer screen than on paper.
Therefore, it is necessary to express that a style sheet, or a
section of a style sheet, applies to certain media types.
There are currently two ways to specify media dependencies for
style sheets:
Specify the target medium from a style sheet with the @media or @import at-rules.
@import url("fancyfonts.css") screen;
@media print {
/* style sheet for print goes here */
}
Specify the target medium within the document language. For
example, in HTML 4 ([HTML4]), the "media" attribute on the LINK
element specifies the target media of an external style sheet:
<head>
<title>Link to a target medium</title>
<link href="foo.css" media="print, handheld" rel="stylesheet" type="text/css"></link>
</head>
<body>
The body...
</body>
</html>
The names chosen for CSS media types reflect target devices for
which the relevant properties make sense. In the following list of CSS
media types the names of media types are normative, but the
descriptions are informative. Likewise, the "Media" field in the
description of each property is informative.
all
Suitable for all devices.
braille
Intended for braille tactile feedback devices.
embossed
Intended for paged braille printers.
handheld
Intended for handheld devices (typically small
screen, limited bandwidth).
print
Intended for paged material and for documents viewed on
screen in print preview mode. Please consult the section on paged media for information about formatting
issues that are specific to paged media.
projection
Intended for projected presentations, for example projectors.
Please consult the section on paged media for
information about formatting issues that are specific to paged media.
screen
Intended primarily for color computer screens.
speech
Intended for speech synthesizers. Note: CSS2 had a similar media type
called 'aural' for this purpose. See the appendix on
aural style sheets for details.
tty
Intended for media using a fixed-pitch character grid (such as
teletypes, terminals, or portable devices with limited display
capabilities). Authors should not use pixel units with the "tty" media
type.
Media type names are case-insensitive.
Media types are mutually exclusive in the sense that a user agent can
only support one media type when rendering a document. However, user
agents may use different media types on different canvases. For
example, a document may (simultaneously) be shown in 'screen' mode on
one canvas and 'print' mode on another canvas.
Note that a multimodal media type is still only one media
type. The 'tv' media type, for example, is a multimodal media
type that renders both visually and aurally to a single canvas.
@media and @import rules with unknown media types (that are
nonetheless valid identifiers) are treated as if the unknown media
types are not present. If an @media/@import rule contains a malformed
media type (not an identifier) then the statement is invalid.
Note: Media Queries supercedes this
error handling.
For example, in the following snippet, the rule on the P element applies
in 'screen' mode (even though the '3D' media type is not known).
@media screen, 3D {
P { color: green; }
}
Note.
Future updates of CSS may extend the list of media types. Authors
should not rely on media type names that are not yet defined
by a CSS specification.
This section is informative, not normative.
Each CSS property definition specifies which media types the
property applies to. Since properties generally apply to several media
types, the "Applies to media" section of each property definition
lists media groups
rather than individual media types. Each property applies to all media
types in the media groups listed in its definition.
CSS 2.1 defines the following media groups:
Problem number 1: Presentation and content are coupled
One of the big selling points of CSS is the separation of
presentation from content. And while I believe that’s still a good thing
to have, not everyone agrees about it’s usefulness. Some time ago Jeff
Croft wrote an article about how unusual it is to only change the CSS
and not the HTML of a site. While he’s mostly making a point of why we
should use a certain CSS framework, there’s a good point hidden there:
Right now it isn’t possible to separate things completely.
Designers have of course known this for centuries. They will tell
you: you need to adapt the design to the content you’re designing. If
you’re building a site for a shampoo, you might use water and bubbles in
your design. If you build a web development blog, you use an image of
blueish sky… ehm… Well, you get the point. Good design adapts to the
content. They are coupled.
You can’t just switch out the content and expect the design to still
work. Sure, you can make small adjustments, and make these available as
alternate stylesheets, but larger changes just doesn’t work. The problem
with the media attribute is that it’s made for big design changes
(switching media), but with no changes in content. How often can you
just restyle a word document to get a powerpoint slide? What about
converting that slide to something nicely viewable on a mobile phone?
That’s what the media attribute is there for.
My point is: switching to another media needs much more than just a
change in design. You need to change the content to fit that media too.
And if you change the content, why not change what stylesheet you link
to? This is why I rarely use the “handheld” or “projection” values.
Problem number 2: Load time
You could think that the browser only loads the one stylesheet that
matches the media it’s currently showing. Not true. All stylesheets, no matter what media they are tied to, are loaded at startup.
This means that the more media types you account for, the longer the load time for any of them will be. Very annoying.
Problem number 3: User agent support
While being able to design for specific user agents might sound like a
good idea, the media attribute still requires user agents to support
it. If a large part of user agents refuse to apply your style using the
media attribute, why not use another method directly? Just to get an
idea of how messy support currently is, you can read the css-discuss summary of the handheld problems:
“Some current phones apply “screen” styles as well as “handheld” styles,
others ignore both, and in some cases the phone carrier runs pages
through a proxy that strips styles out even if the phone could recognize
them, so it’s a crapshoot figuring out what will get applied”
As you see, the value of the media attribute isn’t entirely obvious.
Sure, you might be able to use it for print with good results, but
that’s not all it’s there for. Right?