Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Print This!


WebReview.com: Print This!

Sept. 29, 2000 > Tag of the Week

Print This!

By Chuck Musciano

The history of HTML is somewhat like a romance novel: full of pent up desire and answered prayers. While it is unlikely that the story of HTML will become a bestseller, the latest advance in the standard is sure to quicken the pulse of any HTML author.

At Long Last, Printing

Of all HTML's shortcomings, one of the worst has been a consistent printing model. Even today, Netscape and Internet Explorer print the same page in dramatically different ways, with different page breaks, margins, and layout rules. No matter how much time you spend carefully crafting the exact layout of your page within the browser, you are left helpless as it is transmitted to the printer. Unlike fonts, alignment, tables, and other HTML features that always had some sort of workaround until a standard saved the day, standardized printing has been completely impossible. Until now.

The Cascading Style Sheets Level 2 standard (CSS2) defines, for the first time, a consistent model for managing the printing of HTML documents. This model begins by defining page sizes and layouts, allows you to assign those layouts to your documents, and goes on to let you manage page breaks, widows and orphans, and all the other aspects of printing you've come to know and love.

Over the next several weeks, we'll explore CSS2 printing in detail. To get things started, let's begin with an overview of the rules and properties you'll be using to define and use CSS2 printing features in your documents.

Boxes, Rules, and Properties

The CSS2 model uses a special rule, @page, to define the size and layout of a printed page. This rule has a number of properties that you can use to define everything from a simple page to complex documents with multiple right- and left-side layouts sporting crop marks.

You can define any number of pages in your document, applying them to specific portions of the flow to ensure that your content is printed correctly. For example, you might define a normal portrait page layout for most of the content of your document, but several wide tables require a landscape layout to print correctly. You can assign the appropriate page to each element in your document, ensuring correct printing.

Once you've defined your page layouts, you assign them to elements in your document using the page attribute. If adjacent elements use different page layouts, page breaks are inserted to get the right content on the right page.

Beyond these automatic page breaks between page types, you can use the page-break-before,page-break-after, and page-break-inside properties to cause page breaks to appear where you want them, not where the browser arbitrarily decides they should go. In addition, you can use the orphans and widows properties to control how leading and trailing lines of paragraphs are treated when a page break occurs.

If you've ever managed page layouts and pagination using a tool like Word or WordPerfect, you'll find the CSS2 model easy to use and understand. Even if such printing features are new to you, the CSS2 model makes it simple to get your documents to print correctly, something that was never before possible in HTML. Before all these capabilities give the more delicate among you the vapors, rest up and return next week for an in-depth look at the @page rule.


Chuck is the author of the best-selling HTML: The Definitive Guide and now, the fourth and expanded edition, HTML & XHTML: The Definitive Guide. He also writes on a variety of Internet and Web-related topics for a number of online magazines.


Previously in Tag of the Week

CSS2 Standard Tour: Begin Here
Attribute Sectors in One Quick Bite


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.