like-a-trainee
like-a-trainee

Reputation: 561

CSS: @media print without external css file?

I want to print a html page in a specific way under css. But all the @media print examples seem to have an external .css file I want to be able to do it without an external file which means there will be no link rel tag:

 <LINK REL="stylesheet" MEDIA="print...

How do I do this?

Upvotes: 0

Views: 2915

Answers (3)

Winona
Winona

Reputation: 51

Make sure your closing style tag () has a space between the end of the @media print query and the closing tag. Like so:

@media print {
      stuff {more stuff;}
} </style>

Right curly bracket, space, then closing tag.

Upvotes: 0

Mitchell Layzell
Mitchell Layzell

Reputation: 3058

I would suggest using an external stylesheet but you can how ever do this on the same page as your HTML if you really want to, an example of this would be like so,

HTML / CSS

<!DOCTYPE html>
<html>
    <head>
         <style>
              @media print {

                   /* changes the display property to none on all 
                      p elements when printed */
                   p { display: none}
              }
         </style>
    </head>
    <body>
         <p>I'm here when the page isn't printed</p>
    </body>
</html>

Upvotes: 1

Christopher Parsons
Christopher Parsons

Reputation: 382

Use the @media print query in a CSS style block:

<style>
@media print {
   /* print css here */
}
</style>

Upvotes: 0

Related Questions