Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS @media print not working at all

Tags:

html

css

printing

I'm struggling for hours now why the @media print is not working, I search on Google even on this site and nothing helped, so that's why I post this question. I'm testing it on Google chrome print preview (ctrl p) but i also printed to page and it stays blank.

I try'd to make a separate css file and also a embedded css style into the page.

Here is my code

Headers

<link rel="stylesheet" type="text/css" href="css/reset.css" /> <link rel="stylesheet" type="text/css" href="css/style.css" /> <link rel="stylesheet" type="text/css" href="css/print.css" media="print" /> 

HTML

<div id="bruikleenovereenkomst">     <div id="blo_header">      </div>      <div id="blo_side_top"></div>     <div id="blo_side_bottom"></div> </div>       

CSS normal styles

div#bruikleenovereenkomst {     width:595px;     height:842px;     background-color:#fff;     position:relative; }  div#blo_header {     width:100%;     height:125px;     background-color:#FBE983;     z-index:9 }  div#blo_side_top {     width:57px;     height:420px;     background-color:#B6CAE5;     position:absolute;     right:0;     top:0;     z-index:99; }  div#blo_side_bottom {     width:57px;     height:420px;     background-image:url(../images/leaflet.png);     background-repeat:no-repeat;     position:absolute;     right:0;     bottom:0;     z-index:99; } 

CSS print styles (print.css) note: the div#bruikleenovereenkomst is just a black block for testing.

@media print{      body {         margin:0;     }      h1#logo {         display:none;     }      ul#menu {         display:none;     }      div#bruikleenovereenkomst {         width:100%;         height:500px;         background-color:#000;     }      div#blo_header {         display:none;     }      div#blo_side_top {         display:none;     }      div#blo_side_bottom {         display:none;     }  } 

All I get with printing is just a blank page.

like image 699
Julez Avatar asked Jul 30 '13 09:07

Julez


People also ask

What is @media print 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.

Why are my CSS changes not reflecting?

Browser Cache If you are adding/modifying in-line CSS or JavaScript and not seeing the changes reflected in the HTML source, the page is likely being cached. The solution may be to purge the WordPress object cache, which stores our page caching (Batcache) renders.

Why is my style sheet not working?

Make sure you're linking to your stylesheet using a link tag in the head of the HTML document. <style type="text/css" src="path/to/style. css"> : because it's a similar syntax to the <script> tag, which would make sense, but is invalid. <link rel="stylesheet" src="path/to/style.

How do you write a print page in CSS?

HTML, CSS and JavaScript You can use CSS to change the appearance of your web page when it's printed on a paper. You can specify one font for the screen version and another for the print version. You have seen @media rule in previous chapters. This rule allows you to specify different style for different media.


1 Answers

If you are using @media print, you need to add !important in your styles, or the page will use the element's inline styles that have higher priority.

E.g.

<div class="myelement1" style="display:block;">My div has an inline style.</div> 

In @media print, add !important and be a winner

@media print {    .myelement1, .myelement2 { display: none !important; } } 
like image 171
Richard Avatar answered Oct 03 '22 21:10

Richard