Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting CSS Media Type Inline

I am producing a standalone HTML document under the constraint that the document has to be exactly one file. I would like to use CSS to make sure that links in the document are visible and discoverable (probably blue with underlines) when viewed in a browser, but to vanish most of that formatting when the document is printed.

Is this possible with just a <style> block?

Is it possible to get what I want with JavaScript jiggery-pokery?

like image 607
Brighid McDonnell Avatar asked May 23 '11 17:05

Brighid McDonnell


People also ask

Can I put media query in inline CSS?

It is not possible to use CSS @media rules and media queries in the inline style attribute as it can only contain property: value pairs. According to the W3 specification, the style attribute's value should match the syntax of contents of a CSS declaration block.

What does @media mean in CSS?

The @media CSS at-rule can be used to apply part of a style sheet based on the result of one or more media queries. With it, you specify a media query and a block of CSS to apply to the document if and only if the media query matches the device on which the content is being used.

How do you apply inline style?

An inline style may be used to apply a unique style for a single element. To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS property.


1 Answers

You can use @media or @import in a <style> block and set styles specific to the media type.

Read more here: http://www.w3.org/TR/CSS2/media.html

@media print {
  /* print styles */
  a {color:#333}
}
@media screen {
  /* screen only styles */
  a {border-bottom:1px solid blue}
}
/* general styles here */
like image 135
Wesley Murch Avatar answered Sep 22 '22 22:09

Wesley Murch