Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > CSS

This chapter is from the book

Styling the Document

Basically, we have two main tasks ahead of us:

  • To make the page look like it did when it relied on HTML-based presentation

  • To push the icons to a new level of visual effect by applying some creative CSS to them

Getting Back to Square One

Before we get down 'n' dirty with the links, let's quickly reproduce the original basic design look in CSS. Because we have the HTML file to guide us, we can just rewrite the styles to match what we had before (see Figure 4.3).

<style type="text/css">
body {background: #CEC; color: black;}
td#navbuttons {background: #ACA; padding: 0;
  border: 2px solid #797;}
td#main {background: #FFD; color: black;
  border: 2px solid #797;}
</style>

Figure 4.3Figure 4.3 The first step in re-creating the basic design.a

The space between the two cells is now 4 pixels thick, thanks to the fact that there are two adjacent borders and each is 2px thick. We need to reduce one of them to zero or both to be 1 pixel wide. Let's try the latter:

td#navbuttons {background: #ACA; padding: 0;
  border: 2px solid #797; border-width: 2px 1px 2px 2px;}
td#main {background: #FFD; color: black;
  border: 2px solid #797; border-width: 2px 2px 2px 1px;}

Alternate Border Effects

We also could have created the borders around the cells by setting a background color for the table itself and then setting a value (such as 2) for the cellspacing attribute. Although this approach works in some cases, it also tends to rob the designer of flexibility because it enforces a single padding on all cells instead of allowing different amounts of padding on different cells. That's why we're avoiding it here.

We should also set the vertical and horizontal alignment of the content within the cells. We know that both the icons and the text should be aligned to the top of their table cells, and the icons ought to be center aligned within their cells (see Figure 4.4). Thus:

body {background: #CEC; color: black;}
table#inform td {vertical-align: top;}
td#navbuttons {background: #ACA; padding: 0;
  border: 2px solid #797; border-width: 2px 1px 2px 2px;
  text-align: center;}

Figure 4.4Figure 4.4 Everything's back (more or less) to where we started.

The only thing left to do would be to reproduce the effect of the attribute cellpadding="5" in the original file. We could do that with padding, but we're going to put it off until later when we have a better idea of how the layout might be affected by padding on the cells.

Upgrading the Title

Before we get to the links, we need to make the title fit in with the rest of the design. The design department, you might recall, suggested that we eliminate the space between the text and the table (see Figure 4.5). They probably meant that we should set the bottom margin to zero, but let's take them literally at their word:

body {background: #CEC; color: black;}
h1 {margin-bottom: -0.25em;}
table#inform td {vertical-align: top;}

Figure 4.5Figure 4.5 Get rid of the space between text and table? You got it!

It still doesn't fit in too well, so let's change the color to match the medium-green borders and also switch it to be a sans-serif font. While we're in the area, we'll also boldface it and make sure it's twice the normal text size.

body {background: #CEC; color: black;}
h1 {margin-bottom: -0.25em;
  font: bold 200% Arial, sans-serif; color: #797;}
table#inform td {vertical-align: top;}

There's one more thing that would make this work even better, and that's a thicker top border on the table. Let's make it easy and just add the border to the table itself instead of messing with the table cells (see Figure 4.6).

h1 {margin-bottom: -0.25em;
  font: bold 200% Arial, sans-serif; color: #797;}
table#inform td {vertical-align: top; border-top: 3px solid #797;}

Now it looks like the title is rising from the border itself or maybe was carved out of the same stuff. Whatever visual metaphor it invokes, it's an interesting effect. We'll keep it and see what the client thinks.

Figure 4.6Figure 4.6 Making the title part of the organic whole.

The Icons

The relatively simple nature of the icons (each is a single image alone in a link element) makes them easier to work with. We'll tackle the left-side icons first. We know that each icon is 50x50 pixels. We also know that we want them to sit in the left-side panel with no extra space around them, so we need to convert them to block-level elements with no margin. But we need to be careful about what we convert!

td#main {background: #FFD; color: black;
  border: 2px solid #797; border-width: 2px 2px 2px 1px;}
td#navbuttons a {display: block; margin: 0;}
td#navbuttons img {display: block; height: 50px; width: 50px;}
</style>

This won't have any immediate visual impact, but it avoids trouble in the next step. We want to increase the amount of space around each image, but rather than doing it with margins, let's do it with borders that exactly match the background color of the cell. We'll also set the background color of the images to be transparent so that the cell background remains visible around each icon.

td#navbuttons a {display: block; margin: 0;}
td#navbuttons img {display: block; height: 50px; width: 50px;
  border: 1px solid #ACA; border-width: 5px 10px;
  background: transparent;}
</style>

Okay, so besides adding some apparently empty space around the icons, what good did this do? Plenty. Assume that the current page is the Natural Gas page. We can highlight the icon by adding a rule that makes the border and background the same color as the intracell borders (see Figure 4.7).

td#navbuttons a {display: block; margin: 0;}
td#navbuttons img {display: block; height: 50px; width: 50px;
  border: 1px solid #ACA; border-width: 5px 10px;
  background: transparent;}
td#navbuttons img#gas {border-color: #797; background: #797;}
</style>

The big win we get here is not just that we can easily indicate the current page, but also make the background and border colors change when the link is hovered over by the mouse pointer or when the icon is clicked.

Figure 4.7Figure 4.7 Highlighting an icon with borders and background

Visitation Styles

We'll skip writing a "visited" style for the icons, although we could create one easily enough. As an example, we could have written td#navbutton a:visited {border-color: gray;}..

td#navbuttons img#gas {border-color: #797; background: #797;}
td#navbuttons a:hover {background: yellow;}
td#navbuttons a:hover img { border-color: yellow;}
td#navbuttons a:active img {border-color: #FC0;
  border-style: inset;}
</style>

Two Blocks?

Yes, we've set both the hyperlinks and the images to be block-level elements. By making both elements blocks, we can be assured that they'll behave in a predictable way—sort of like one div inside another. If we left the images alone, they would default to being inline elements, which can cause unexpected space to appear in recent browsers.

Now any link (other than the one for the current page) will get a yellow background when hovered over. If an icon is clicked, its border will turn orange, thus framing the link for a moment in a thick orange box with the yellow background still visible inside (see Figure 4.8).

Figure 4.8Figure 4.8 Combining hover and active styles can lead to interesting effects.

It's worth spending a moment on the selectors. Take, for example, td#navbuttons a:hover img. It's written this way because we want to give a yellow highlight to any image that's descended from a link being hovered over—both of which are contained within a td element with an id of navbuttons. Ditto for the "active" rule.

It's worth asking, though, why we set the background color on the hyperlink instead of for the image itself. It turns out that IE5.x for Windows mostly ignores background styles on images that are part of hovered links. This failure is very odd because it will change the border color, but there you have it. Because IE5.x will set the background color of the hyperlink, we can sneak around this bug in the manner shown. If you're developing for a situation in which IE5.x isn't an issue, you could just style the background of the image and not mess with the link's background at all.

No Hover for the "Current" Icon

So why doesn't the icon for the current page (the gas flame) take on the hover or active styles? Because the specificity of its selector (td#navbuttons img#gas) outweighs the selectors for the hover and active states, so its values for the border and background colors win out.

Altering the Main-Text Links

With the left-side icons working the way we'd like, let's give the text links a makeover. Our first order of business is to define a "baseline" for the text links. Typically, designers will change the color of a link in its various states, and sometimes they'll forcibly remove the underlines.

In this case, we're just going to change the colors but leave the underlines alone. That way, the user's preference setting regarding link underlining will hold sway, which will help them recognize links for what they are. Because the blue doesn't really work with our green-and-sand color scheme, though, we're going to make the links a dark green when unvisited and dusky purple when visited. Just to make sure the links stand out, let's boldface them as well.

td#navbuttons a:active img {border-color: #FC3;
  border-style: inset;}
a:link, a:visited {background-color: transparent; font-weight: bold;}
a:link {color: #171;}
a:visited {color: #747;}
</style>

Now we need a good hover style. Actually, we need two good hover styles: one for unvisited links and one for visited links:

a:visited {color: #747;}
a:visited:hover {color: #FFD; background-color: #747;}
a:link:hover {color: #FFD; background-color: #797;}
</style>

Splitting Up the Styles

We split the styles between the a:link, a:visited rule and the a:link and a:visited rules to keep them as simple as possible. Otherwise, we would have been duplicating the background-color and font-weight styles for both link states, which doesn't make much sense.

Now we get a reverse-text effect on all our links. In CSS2-aware browsers, we'll get yellow-on-green for hovered unvisited links and yellow-on-purple for hovered visited links (see Figure 4.9). It doesn't matter what order these rules come in because they can never conflict with each other. That's because a link can't be both visited and unvisited.

Figure 4.9Figure 4.9 When changing the appearance of links, it's best to make sure they still stand out.

Dealing with Explorer

If you use the form of "chained" selector shown for your hover styles, make sure you put the default second—that is, whichever hover style you'd prefer to be applied to all links in a document, visited or otherwise. Explorer doesn't understand this syntax, so it will treat all such rules as if they're simple a:hover rules.

Another problem you might encounter in Explorer is that it thinks the last link that was clicked is still active. Therefore, if you click a link and then hit the Back button, the page will come up with the link still in the active state even though it isn't active. Given this fact, you might want to avoid writing a:active styles if Explorer users will make up a big portion of your audience.

Help! A Press Release!

Now that we've done the basic style work on text links, let's jazz up the help and press-release links. The icons are cute enough, but we can do something a lot more interesting than having these graphics embedded in the page itself.

The first thing we need to do is remove the icons from the HTML and create taller versions—say, 32 pixels high instead of 16. The important thing is that the icons should be an even number of pixels tall.

NOTE

"Taller" images already exist in the files you downloaded from the Web site: help-icon.gif and pr-icon.gif.

Now let's put a border around the help link, place the icon in the background, position it on the left side and centered vertically, set padding to keep the text from overlapping the icons, and also change the text and background colors to go along with it (see Figure 4.10). Oh, and just for the heck of it, we'll eliminate the underline, too.

Figure 4.10Figure 4.10 Taking a text link from "blah" to "boo-yah!"

a:link:hover {color: #FFD; background-color: #797;}
a.help:link, a.help:visited {padding: 0 2px 1px 16px;
  background: #FDD url(help-icon.gif) left center no-repeat;
  color: #733; border: 1px solid #C66;
  text-decoration: none;}
</style>

By aligning the background image with the left centerpoint of the link (using the keywords left center), we can make it look like it's inline. As for the padding, it helps keep the borders pushed a little bit away from the text and opens up enough space on the left to show the background image. It's easy enough to adjust the padding as necessary (for example, to close up the space between the edge of the icon and the text).

Removing the Images

Remember to remove the img elements from the help and press-release links in the HTML document itself. If they're left in, they will obscure the background images we're inserting and greatly interfere with the intended effect.

It looks like the icon is still part of the document, and that's exactly what we want. The advantage of putting it in the background of the link, of course, is that we can easily change it later without having to touch the document source. We might decide to put the icon on the right side of the hyperlink, for example. Doing that would be a simple matter of changing the values for padding and background—nothing more.

Let's give the same treatment to the press-release link, using its icon and colors to match:

a.help:link, a.help:visited {padding: 0 2px 1px 16px;
  background: #FDD url(help-icon.gif) left center no-repeat;
  color: #733; border: 1px solid #C66;
  text-decoration: none;}
a.pr:link, a.pr:visited {padding: 0 2px 1px 16px;
  background: #EEC url(pr-icon.gif) left center no-repeat; 
  color: #171; border: 1px solid #797;
  text-decoration: none;}
</style>

The only real differences are in the colors and the image; otherwise, everything's the same. Now all we need are some good hover effects for the links, and we'll be golden (see Figure 4.11):

a.pr:link, a.pr:visited {padding: 0 2px 1px 16px;
  background: #EEC url(pr-icon.gif) left center no-repeat; 
  color: #171; border: 1px solid #797;
  text-decoration: none;}
a.help:hover {color: #FFD; background-color: #C66;}
a.pr:hover {color: #FFD; background-color: #797;}
</style>

Figure 4.11Figure 4.11 Now there are two way-cool links for our viewing pleasure.

Changes on Hover

In theory, you could also change the background image in the hover state, but Explorer 5.x for Windows doesn't handle hover-based changes very gracefully. Its usual behavior is to change the background image when you hover over a link and then keep the hover image after the mouse moves off the link. Sadly, there doesn't seem to be a CSS-based way around this bug.

Now let's create some "visited" styles for our way-cool links. We could do the usual and change the various colors, but let's take it a step further and display a different background image—thus, changing the icon for visited links.

The basic need here is for new images. We'll go with ones that look "washed out" because they're the easiest to produce. Then all we need to do is create the styles to drop them into place when a link's been visited, as well as some color shifts.

a.pr:link, a.pr:visited {padding: 0 2px 1px 16px;
  background: #EEC url(pr-icon.gif) left center no-repeat; 
  color: #171; border: 1px solid #797;
  text-decoration: none;}
a.help:visited {color: #A88; background-color: #EDD; 
  background-image: url(help-vicon.gif);}
a.pr:visited {color: #797; background-color: #DDC; 
  background-image: url(pr-vicon.gif);}
a.help:hover {color: #FFD; background-color: #C66;}

NOTE

Look for the files help-vicon.gif and pr-vicon.gif in the files you downloaded from the Web site. These are the washed-out versions of the link icons we've been using (see Figure 4.12).

Figure 4.12Figure 4.12 Visitation changes: Washing out a link after it's been visited helps users remember where they've been.

Of course, we could have used any icon at all—one with a little "X" over the icon, maybe an inverse image in which the colors are all reversed, or really anything. The only limitation is what you can fit into the space.

Order in the Link States

We've added the various link states in a specific order in this project: link, visited, hover, active. In general, maintaining this order is critical because changing it causes link styles to stop working. The order of LVHA has a few mnemonics you can use: "LoVe-HA!" and "Like Various Hairy Apes" are two particularly memorable ones.

A Touch of Cleanup

If you look closely at the text above and below the jazzed-up links, you can see that it comes very close to the borders of the links. This is because when you set a border on an inline element (such as a hyperlink) and then give it some top and bottom padding, the border will get pushed into other lines of text. The lines won't get pushed apart. If you set the padding large enough, the box will start overlapping other lines or being overlapped by them.

Given this fact, and also seeing that the paragraphs are snuggling up to the edges of the table cell, let's give it some margins and increase the height of the text lines:

td#main {background: #FFD; color: black;
  border: 2px solid #797; border-width: 2px 2px 2px 1px;}
td#main p {margin: 0.75em 1.5em; line-height: 1.33em;}
td#navbuttons a {display: block; margin: 0;}
td#navbuttons img {display: block; height: 50px; width: 50px;
  border: 1px solid #ACA; border-width: 5px 10px;
  background: transparent;}

With this last change, we're ready to dazzle the client with our new design! The complete style sheet is shown in Listing 4.1, and the result is shown in Figure 4.13.

Figure 4.13Figure 4.13 Making the text a little easier on the eyes.

Listing 4.1 The Complete Style Sheet

<style type="text/css">
body {background: #CEC; color: black;}
h1 {margin-bottom: -0.25em;
  font: bold 200% Arial, sans-serif; color: #797;}
table#inform td {vertical-align: top; border-top: 3px solid #797;}
td#navbuttons {background: #ACA; padding: 0;
  border: 2px solid #797; border-width: 2px 1px 2px 2px;
  text-align: center;}
td#main {background: #FFD; color: black;
  border: 2px solid #797; border-width: 2px 2px 2px 1px;}
td#main p {margin: 0.75em 1.5em; line-height: 1.33em;}
td#navbuttons a {display: block; margin: 0;}
td#navbuttons img {display: block; height: 50px; width: 50px;
  border: 1px solid #ACA; border-width: 5px 10px;
  background: transparent;}
td#navbuttons img#gas {border-color: #797; background: #797;}
td#navbuttons a:hover {background-color: yellow;}
td#navbuttons a:hover img {border-color: yellow;}
td#navbuttons a:active img {border-color: #FC3;
  border-style: inset;}
a:link, a:visited {background-color: transparent; font-weight: bold;}
a:link {color: #171;}
a:visited {color: #747;}
a:visited:hover {color: #FFD; background-color: #747;}
a:link:hover {color: #FFD; background-color: #797;}
a.help:link, a.help:visited {padding: 0 2px 1px 16px;
  background: #FDD url(help-icon.gif) left center no-repeat;
  color: #733; border: 1px solid #C66;
  text-decoration: none;}
a.pr:link, a.pr:visited {padding: 0 2px 1px 16px;
  background: #EEC url(pr-icon.gif) left center no-repeat; 
  color: #171; border: 1px solid #797;
  text-decoration: none;}
a.help:visited {color: #A88; background-color: #EDD; 
  background-image: url(help-vicon.gif);}
a.pr:visited {color: #797; background-color: #DDC; 
  background-image: url(pr-vicon.gif);}
a.help:hover {color: #FFD; background-color: #C66;}
a.pr:hover {color: #FFD; background-color: #797;}
</style>

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020