Simply Put the agency blog

Posts Tagged ‘css’

Make your website printer-friendly

February 14th, 2008 by Verne

The accessibility of your website is an important consideration to make. It could be as simple as determining what screen resolution your website is compatible with. The ongoing cross-browser compatibility struggle can also be seen as an accessibility issue, as can the extent that your website complies with screen reader standards for the blind. Essentially, the accessibility of your website is measured by the number of methods, mediums, and audiences that your site’s content can be easily transferred to.

icon-printer.jpgAccessibility also includes, among many other things, the extent to which your site is printer-friendly. In other words, the ability for your audience to print your content and take it with them so that they may have access to it while away from the computer. As with all aspects of accessibility, making your site printer-friendly is ideal, but not manditory. Sometimes it’s just not necessary - like an artist’s online portfolio. Other times, like with real estate listings on an agent’s website, it just makes sense.

When we were working on the recently-launched MichelleLuDo.com website, we thought about the nature of the audience that Michelle, a friendly and driven real estate sales agent, would be interacting with through her new website. What we discovered was that her clients were more traditional individuals and were likely to prefer print over web when it came to digesting information. Moreover, when you consider the steps an individual on a real estate agent’s website intuitively takes - browse a listing, find something interesting, copy the information down, visit the location - ensuring the website’s content was printer-friendly became a priority.

How to make a website printer-friendly

Making a website printer-friendly is actually quite simple. All it takes is two stylesheets - one to tell the browser how to display your website on the screen, and one to tell the printer how to print it out. You define which is which using the media attribute in the <link> tag that resides in your <head>. For example, here’s how MichelleLuDo.com’s stylesheet links generally look:

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<link rel=”stylesheet” href=”style-print.css” type=”text/css” media=”print” />

As you can see, we loaded 2 stylesheets and defined one as media="screen" and the other as media="print".

Once you’ve got the two stylesheets setup, it’s time to format them to your liking. Your print stylesheet should start by being identitcal to your screen stylesheet. Then begin hiding all the elements that you don’t want to show up in your print out using either display: none; or position: absolute; left: -9999px;. In most cases it’s best to use the latter method to hide elements as screen readers sometimes ignore display: none;. However, in this case, it shouldn’t make a difference.

Best practices for printer-friendly websites

Here are 5 best practices to follow when deciding how the print version of your website should appear:

  1. Strip all or most images.
  2. Remove background colors.
  3. Minimize and adjust text colors - use colors that will be easy to read on paper.
  4. Remove unecessary or irrelevant elements (such as links).
  5. Add necessary information such as the webpage’s URL or contact information.

Tip: Trading Places

Here’s a simple tip that will help you swap web content that is irrelevant or unfriendly for print with useful and printer friendlier content.

For example, here is the header image on MichelleLuDo.com:

MichelleLuDo Header Image

In the printed version of the site we wanted to make sure that her name was still visible and that branding stayed in tact. However, printing this image would not be too friendly on the printer’s ink or on the overall aesthetics of the print out (since all other background colors will have been stripped). What we want to do is replace the header image above with this printer friendly header image in the printed version of the website:

MichelleLuDo.com Header Image (Printer Friendly)

So here’s how we do it:

HTML

<div id="header-image">
<span class=”normal”><a href=”/” title=”Michelle Lu-Do”><img src=”id.jpg” alt=”Michelle Lu-Do”></a></span>
<span class=”pf”><img src=”id_pf.jpg” alt=”Michelle Lu-Do”></span>
</div>

Screen Stylesheet

#header-image { padding-top: 40px; float: left; display: block; width: 530px; height: 41px; }
#header-image .normal { }
#header-image .pf { display: none; }

Note that the <span class="pf"> that wraps our printer-friendly header image (id_pf.jpg) is hidden using display: none;, while the <span class="normal"> that wraps our web-ready header image is displayed.

Print Stylesheet

#header-image { padding-top: 40px; float: left; display: block; width: 530px; height: 41px; }
#header-image .normal { display: none; }
#header-image .pf { }

Notice now that .normal and .pf have traded properties and now the ‘normal’ web-ready header image is hidden while the printer-friendly header image is displayed for the printer. Just like that, our printer-friendly image has traded places with the web-friendly image. You can use this hepful tip with any content on the page.

The final product

Here’s a live page from MichelleLuDo.com:

MichelleLuDo.com

And here’s how the page prints out:

MichelleLuDo.com (Printed)

And there you have it, an accessible printer-friendly website.

9 Comments

Tags: , ,

Vertically center content with CSS

January 31st, 2008 by Verne

A convenient benefit of using tables is the ability to vertically center content within a cell using the valign attribute. Unfortunately, acheiving the same effect with CSS isn’t so convenient. So, as we continue to move towards tableless structures, there comes a need for a simple and valid CSS alternative. There have been a number of ways to approach this feat, but in this tutorial, I will lay out the technique we use to vertically center content using CSS.

The HTML

Three divs are required in order to pull this one off. Here’s an example of how we setup the divs.

<div id="container">
<div id=”position”>
<div id=”content”>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec laoreet egestas mi. Aliquam erat volutpat. Aliquam erat volutpat. Suspendisse potenti. Suspendisse potenti. Vestibulum mi nibh, hendrerit nec, feugiat vitae, feugiat a, nisl.
</div>
</div>
</div>

The #container div is used as the main reference point for centering the content. In other words, the content will be vertically centered against the height of the #container div.

The #position div is used to, naturally, position the content.

Finally, the #content div is used to encase the actual content that we are trying to center. This div is also used to correct the positioning of the content for Internet Explorer users (as you’ll see later).

The CSS

Here’s the CSS we apply to make it all come together:

<STYLE type="text/css">
#container { width: 100%; height: 100%; display: table; }
#position { display: table-cell; vertical-align: middle; width: 100%; text-align: center; }
</STYLE>

We’ve defined the height of #container to be the full height (100%) of the page. We could have just as easily given it a fixed height such as 500px. We’ve also added display: table and display: table-cell to #container and #position, respectively, which will tell it to mimic the properties of <table> and <td>.

You’ll notice that we haven’t applied any style to the #content div. This is because browsers like Firefox and Safari are able to use the uber handy vertical-align: middle property, making it almost just as easy as using tables. Using only the code we’ve shown thus far, our content should be nicely vertically centered on the page in all browsers except Internet Explorer, which doesn’t understand vertical-align: middle.

To correct this problem and ensure that our content is still vertically centered for IE users, we’ll apply the following conditional statements and extra bits of CSS.

<!--[if IE]>
<STYLE type="text/css">
#container { position: relative; }
#position { position: absolute; top: 50%; }
#content { position: relative; top: -50%; }
</STYLE>
<![endif]–>

The <!--[if IE]> … <![endif]–> tags tell the browser to only process this CSS if the browser being used is Internet Explorer.

When processed, the CSS places the top margin of the #position div halfway down the height of #container. However, this only places the content in the lower half of #container. So, to center it vertically, #content’s top is offset by -50%. That is, it is being shifted upwards a distance that is equal to 50% of its height. If you do the math and crunch the numbers in your head, you’ll find that this does a nice job of centering the content.

Live Demo

A live demo of this tutorial is available here. You can also download the demo page for your reference.

33 Comments

Tags: ,

Site of the Day

January 9th, 2008 by Verne

I woke up this morning with a pleasant surprise - our site (www.vdotmedia.com) was chosen to be Site of the Day over at The Daily Slurp! In addition, our new has also been featured over at CSS Mania, Most Inspired, and CSS Creme - all popular website galleries that celebrate and showcase modern websites designed and developed in valid CSS/XHTML.

Site of the Day

Aside from the great exposure from being featured on the front page of these high-traffic sites, these galleries are a great tool for designers to find inspiring work from all around the world. I encourage everyone to give them a browse (and vote for our site while you’re at it!).

2 Comments

Tags: