|
SubMenu
Tutorial Stats
Made by: ForterOn: 6-7-2007 13:39Total views: 1487Replys: 0Catagory: AdvancedType: CSSSubject: special featuresAdvertisement
|
CSS Tutorial
Print stylesheet in CSSThere are a lot of websites on the internet with articles or other stuff that you might
want to print. But when you click the print button on your browser, the results are
usually crappy. The printed page will show banners, menus, ads and parts of the text
are cropped off.
The basic ideaThe html style and link tags that are used for placing css in the html, both use the
media attribute, which allows you to specify the devices on which the stylesheet should
be used. The idea is that we make one style sheet for the website and another one for
printing so we can specify the things that should be shown on each device.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>css example</title>
<style media="screen">
.screen_output {
display: inline;
}
.print_output {
display: none;
}
</style>
<style media="print">
.screen_output {
display: none;
}
.print_output {
display: inline;
}
</style>
</head>
<body>
This page is viewed on a
<span class="screen_output">computer screen</span>
<span class="print_output">printed page</span>
</body>
</html>
Tips and tricks for printable htmlThere are a few things that should be kept in mind when creating a print stylesheet:
A basic exampleNow its time for a real example. I could explain every part in detail, but the html
would take up a lot of space, so i will just give you the source code and the result.
If you want to see the outcome then go to
test.html a create a print preview.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Css print example</title>
<link rel="stylesheet" href="style_screen.css" type="text/css" media="screen"></link>
<link rel="stylesheet" href="style_print.css" type="text/css" media="print"></link>
</head>
<body>
<div class="head">
<div class="head_title">Css print example</div>
</div>
<div class="menu">
<a href="" class="menu_option">home</a>
<a href="" class="menu_option">search</a>
<a href="" class="menu_option">about</a>
</div>
<div class="print_title">
Printed from: www.blizaga.com<br />
Printed on: 04-07-2007 13:13<br />
<br />
</div>
<div class="field">
This is the main content.<br />
This is another part of the main content<br />
</div>
</body>
</html>
The style_screen css:
body {
padding: 0px;
margin: 0px;
}
.head {
display: block;
background: #81bcf5;
border-bottom: 2px solid black;
margin-bottom: 10px;
}
.head_title {
font-size: 24px;
font-family: arial;
color: white;
line-height: 60px;
padding-left: 20px;
}
.menu {
display: block;
float: left;
width: 180px;
border: 2px solid black;
border-bottom: 1px solid black;
border-left: none;
margin-right: 10px;
background: #f3dba5;
}
.menu_option {
display: block;
padding-left: 3px;
font-family: arial;
font-size: 12px;
font-weight: bold;
color: black;
border-bottom: 1px solid black;
}
.menu_option:hover {
background: white;
}
.print_title {
display: none;
}
.field {
display: block;
width: 400px;
padding-top: 4px;
font-family: arial;
font-size: 14px;
}
And the style_print.css:
.head {
display: none;
}
.menu {
display: none;
}
.print_title {
display: block;
font-size: 11pt;
font-weight: bold;
font-family: arial;
}
.field {
display: block;
font-family: arial;
font-size: 11pt;
}
If we now view test.html (test.html), we will see the following things:
|