Why It's Not Bulletproof
Getting back to my helpful reader's e-mailyou know, the one who wisely disables images when he browses on a slow dial-up connectionthe reason for his note was to
Because the content's text color was two shades of gray, when the tiled image was removed (or disabled by the reader) the text was left sitting on the default background
Figure 6.5 shows what happens when the tiled image is removed. There's not exactly an optimal contrast between the text in the main column and the background color, which makes it difficult to read. But even worse, the right column's text disappears completely because it's the same color as the background. Figure 6.5. It's difficult to read and, wait, where did the right column go?
For users who browse with images turned off to
|
A Bulletproof Approach
To ensure that your page's text is still readable, even in the absence of images, the bulletproof fix is rather simple. Remember to always provide
background
For instance, looking back at our unreadable example, if I had simply added background color to content areas of the page, my helpful reader would still be able to view the text without any problems. Since the content portion of the page sits on top of a white background, I need to add that color to the containing <div id="content"> that wraps that column:
#content {
background: #fff;
}
Similarly, since the sidebar's text sits on top the light-gray background portion of the tiled image, I just need to declare that color for the <div id="sidebar"> that wraps the right column:
#sidebar {
background: #eee;
}
Figure 6.6 shows the results of adding those two simple rules to the style sheetwith images still turned off . You'll notice that while the tiled image is gone, each text column has a background color sitting behind it, masking the dark gray default of the entire page. Figure 6.6. With background colors added, the text is readable once again.
|
Why It's Bulletproof
By taking the extra time (and we're talking seconds here) to provide equivalent background colors for any images used as backgrounds, you'll make your site one step closer to being bulletproof. Users who visit your pages with images turned off to
Bulletproof means
being prepared for whatever is thrown at your design
. This is just one small, easy step that can help ensure your design doesn't break down when
To
Figure 6.7. On simplebits.com, "About Sections" and "Bits to Buy" are contained in <h3> elements.
The "About Sections" and "Bits to Buy" headings are contained in <h3> elements (i.e., <h3>About Sections</h3> ), while a subtle background fade image is placed behind the white text. The CSS to achieve this for the top (green) heading looks like this:
#sidebar h3 {
margin: 30px 0 12px 0;
padding: 5px 10px;
color: #fff;
font-size: 120%;
background: url(http://flylib.com/books/2/68/1/html/2/img/sub-h-bg.gif) repeat-x top left;
}
Where sub-h-bg.gif provides the green fade background, the text on top of it is white. The page's default background color is also white. I think you can see where I'm going with this.
If we were to
Figure 6.8. The magically
|