Skip to content Skip to sidebar Skip to footer

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 wh

Solution 1:

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>

Solution 2:

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

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

Solution 3:

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.

Post a Comment for "Css: @media Print Without External Css File?"