HTMLGoodies
The ultimate html resource
Earthweb.com


About the Double-Underlined Links


Become a Partner




Search Clipart.com:



internet.commerce















HTML Goodies : Beyond HTML : Cascading Style Sheets: CSS and Printing

HTML GOODIES TO GO NEWSLETTER


Other Related Newsletters

CSS and Printing


By Joe Burns

Use these to jump around or read it all...
[Page Break]
[The Format]
[Setting A Specific Page Break]

I get a lot of questions asking if there are ways to "force" people's browsers to do certain things. The events most often asked for are to force a browser to bookmark the page, to set user preferences, and this one: How can I force a person's browser to print my page?

The short and truthful answer is that you can't. There's no command or tag, to my knowledge, that produces a print when your page loads. There are just too many factors involved. Is the user's printer turned on? Can the Web page fit nicely in the print space set by the viewer? And most importantly: Does the viewer want to print your page? It would cheese me if I logged into your page and all of a sudden my printer was humming.

     Update! As of 10/99 there is still no way to force a printer to print a page; however, you can initiate a print request. See the tutorial.     

You can take some control when the user decides he or she does want to print your page. Through the magic of Style Sheets, you can now make a point of indicating where the pages will break during the print process.

     As of 12/21/98, this CSS2 command is supported only by Internet Explorer browsers version 4 and above.


Page Break

There are two commands you're worried about here:

page-break-after

page-break-before

You can pretty much pick out what each does. The first sets the printing page break just before the element, the second sets the page break just after.

Each command has, in theory anyway, four attributes:

always | auto | left | right

  • always tells the browser to break the print page after this element always.
  • auto is the default. You're telling the browser to do what it would do anyway: Page break where the page ends.
  • left is not supported by any browser yet. It is used if your printer will print both sides of a page, like a manuscript. If the page is a left-facing page, use this attribute.
  • right is what you use if it's a right-facing page.


The Format

Here's what it looks like in your page's <HEAD> tags:

<STYLE TYPE="text/css">
     H2 {page-break-before: always}
</STYLE>

That format will produce a print page break before each H2 on the page. Would you like to try it out? This page has four H2 headings. Go ahead and print the page. Each H2 will use a new page and will act as the Header for the printed page. Remember, though, that you have to be using Internet Explorer 4 or better.


Setting A Specific Page Break

Maybe it's better not to have every H2 break the page. Maybe you'd like a page break at a specific point to keep a particular look. You do that by setting up a class of page breaks.
     You can set up the class on any HTML command, but I think the best method is to set up the class within a <BR> or <P> command. That way there's some white space where the page can break. Here's a look at the format (this will sit between your <HEAD> tags):

<STYLE TYPE="text/css">
     P.breakhere {page-break-before: always}
</STYLE>

This then will be the activator for the page break:

<P CLASS="breakhere">

You can set up as many different classes as you'd like as long as you keep following the same format as above.


And That's That...

This is another one of those commands that I would use if there's a need for it, regardless of the type of browser the viewer is running. Those that understand the command get the effect, and those that don't just get a straight page print. Either way, the user gets a nice print of the page. It's just that in one of the prints, you're able to set a few parameters.

 

Enjoy!

Tools:
Add htmlgoodies.com to your favorites
Add htmlgoodies.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

IT Management Networking & Communications Web Development Hardware & Systems Software Development Earthwebnews.com



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES