Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify CSS media types in the style attribute?

Tags:

css

I was wondering if I can specify any CSS media types in the style attribute? and what can I specify in the style attribute?

like image 878
HELP Avatar asked Nov 05 '10 01:11

HELP


People also ask

Can we write media query in style tag?

Media queries work fine inside style tags and always have. They don't work in style attributes as only property/values are allowed in style attributes. You should avoid using the style attribute anyway unless you have a special case reason.

Which attribute specifies the media type of the style tag?

The media attribute specifies what media/device the CSS style is optimized for. This attribute is used to specify that the style is for special devices (like iPhone), speech or print media. Tip: This attribute can accept several values.

Can we give media query in inline CSS?

Yes, this is quite possible but only as using javascript event attributes in HTML elements.


1 Answers

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.

like image 83
wsanville Avatar answered Oct 05 '22 04:10

wsanville