Can I specify CSS media types in the style attribute?
I was wondering if I can specify any开发者_JAVA百科 CSS media types in the style attribute? and what can I specify in the style attribute?
Not that I know of. Your best bet is to define a class
rather than inline styles. Then, you'll have more flexibility.
You can include different stylesheets by specifying the media
attribute on your link
tag to include a stylesheet, or you can also specify that rules within a stylesheet should only apply to a given media.
For example:
Including a CSS file by specifying a media:
<link media="print" href="styles.css" type="text/css" rel="stylesheet">
Specifying a media within a stylesheet:
@media print
{
.myStyle { display: none; }
}
Also, see the W3C media type list for all your options.
You can't specify media type, but you can specify whatever CSS properties the element will support.
Media types is specific to style sheets only, per the w3 css specification:
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.
Ref: http://www.w3.org/TR/CSS21/
The only thing that can be specified in the style attribute is property:value pairs for styling the specific element.
You can specify a ;
delimited list of property: value
pairs. You can not include the media type.
99% of the time, you are better using an external stylesheet. I use style
attribute mainly for animating the element via JavaScript. Occasionally I use the style
to specify a background image (where it is dynamic and echo'd to the markup), where it would be too cumbersome to add a preprocessor to my raw CSS files.
精彩评论