Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

not printing div via css 1

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
I have a div that I want to not have printed when a page is printed... anyway to leave it out via css?

[conehead]
 
Create an alternative stylesheet and have that particular div set to display:none;
 
not sure I understand... how do I have it displayed on the monitor, but not printed via display: none

[conehead]
 
Small example:

Code:
<html>
<head>
<STYLE MEDIA='print'>
div.screenOnly{
 display:none;
}
</STYLE>
</head>
<body>
abc<div class='screenOnly'>xyz</div>
</body>
</html>

The style section with media='print' would contain only
those styles intended for printing. If you also wanted the background of that particular div to be blue, for example, you would have to create another stylesheet with the media set to 'screen':

Code:
<html>
<head>
<STYLE MEDIA='print'>
div.screenOnly{
 display:none;
}
</STYLE>

<STYLE MEDIA='screen'>
div.screenOnly{
 background:blue;
}
</STYLE>
</head>
<body>
abc
<div class='screenOnly'>xyz</div>
</body>
</html>

In this example, the div background is blue on screen, but invisible on the printout.

For more details:
Good luck!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top