Forum Moderators: not2easy
Also (while I'm here), I've tried every which way to change my font to serif for the printed page but have been unsuccessful. What could be interfering with the simple font styles in the print css?
Thanks!
NB
Instead I use inside the normal extrenal CSS file:
@media print {
.title {padding: 0;}
.interactive, #crum, .ads {display:none;}
}
Make sure specificity is high enough.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
body {
font-family: arial, helvetica, sans-serif;
}
table {
border-collapse: collapse;
margin: 10px;
}
table td, table th {
border: 1px solid black;
}
@media print {
table td, table th {
border: none;
}
body {
font-family: serif;
}
}
</style>
</head>
<body>
<h1>TITLE</h1>
<table>
<tr><th>11</th><td>12</td><tr>
<tr><td>21</td><td>22</td><tr>
</table>
</body>
</html>
Here's the style code:
<style type="text/css">
@media print {
table td, table th {
border: 1px;
border-color: #000000;
}
body {
font-family: serif;
}
}
</style>
Any thoughts?
Also a shorthand notation like border is trickier than it might seem as it reset the other values it could set to their default, I'd be carful wielding it..
Anyway this works in FF, Opera and Safari:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
body {
font-family: arial, helvetica, sans-serif;
}
table {
border-collapse: collapse;
margin: 10px;
}
table td, table th {
border: none;
}
body h1 {
color: red;
}
@media print {
table td, table th {
border: 1px solid black;
}
body {
font-family: serif;
}
h1 {
color: green;
/* specificity prevents this from being used */
}
}
</style>
</head>
<body>
<h1>TITLE</h1>
<table>
<tr><th>11</th><td>12</td><tr>
<tr><td>21</td><td>22</td><tr>
</table>
</body>
</html>
Note that I use the same selectors (i.e. same specificity) where I override it in the print style and that the print styles come AFTER the normal style.
Note that I changed the color of the h1 to red in the normal style with a higher specificity than I'd normally do, and that overruling it now with a lower specificity selector in the print sheet doesn't work anymore. It stays red in print.
You can used linked styles instead of adding the CSS in the header as I do in these small examples.
Build it up from something simple. always make sure your code is valid, and keep an eye on specificity and order (if the specificity is the same).
@media print {
table, table tr, table td {
border-top: #000 solid 1px;
border-bottom: #000 solid 1px;
border-left: #000 solid 1px;
border-right: #000 solid 1px;
}
}
Thanks for your help!