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

Home > Articles

This chapter is from the book

Styling the Document

There are so many possibilities that it's hard to decide what to do first. Still, we have to start somewhere, so let's begin at the top of the calendar and then work on the grid of dates.

Setting the Top Apart

It's probably easiest to set the row of day names apart by reversing the content to be light blue text on a dark blue background. While we're at it, we'll get rid of the table-structure styles:

<style type="text/css">
tr#days th {color: #CCE; background-color: #224;

      font-weight: bold; text-align: center;

      padding: 1px 0.33em;}
</style>

The padding fills out the labels a little better and thus prevents them from jamming up next to each other. Now would be an excellent time to tie together the row of day names and the title immediately above it. Let's give it a light blue background, center and boldface the text, and put a border on the cell that matches the background color for the row of days. While we're at it, let's bump up the font-size just a bit.

<style type="text/css">
tr#days th {color: #CCE; background-color: #224;
   font-weight: bold; text-align: center;
   padding: 1px 0.33em;}
tr#title th {background: #AAC; color: black;

      border: 1px solid #224; font-size: 120%;}
</style>

Now we have a calendar top that all fits together (see Figure 3.4). Of course, if you don't like blue, you can always change the color values, but you might want to wait until we're done to decide that.

03css04.jpg

Figure 3.4 The calendar now has a well-styled top.

Creating the Grid

Even though the main part of the calendar, the grid of days, is part of a table, there aren't any borders between the numbers yet. We can fix that, but it isn't as simple as you might think at first. For example, we could simply give every td element a border, but the results aren't likely to be quite what we want (see Figure 3.5):

tr#title th {background: #AAC; color: black;
   border: 1px solid #224; font-size: 120%;}
td {border: 1px solid gray;}
</style>
03css05.jpg

Figure 3.5 Borders on table cells don't overlap, so many appear to be doubled in thickness.

Because each cell has four borders of its own, any place two cells adjoin each other, their borders are going to be placed right next to each other. Therefore, inside the table, the borders between cells add up to be 2 pixels thick, whereas the ones along the outside are only 1 pixel thick.

There are two ways to deal with this. One is to only style two borders—say, the right and bottom borders—and make sure the other two borders have no width. The other way is to manipulate the colors of the borders so that the borders all look roughly the same but each cell still has all four borders "turned on." We're going to choose the latter route for reasons that will become obvious later in this project.

tr#title th {background: #AAC; color: black;
   border: 1px solid #224; font-size: 120%;}
td {border: 1px solid gray;
   border-color: #BBB #EEE #EEE #BBB;}
</style>

We're working in shades of light gray to produce a subtle inset-border effect. Therefore, the top and left borders get a darker shade than the bottom and right borders. (We're assuming that the virtual light source is coming from the top left.) The problem is that the right borders on the last column will be a very light gray, making it look like the calendar grid isn't closed. To fix this, we'll set a different style for the right border of only the cells in that column (see Figure 3.6):

td border: 1px solid gray;
   border-color: #BBB #EEE #EEE #BBB;}
td.sat {border-right: 1px solid #BBB;}
</style>
03css06.jpg

Figure 3.6 Subtle color variations make the grid less obtrusive.

You can see that the cells along the bottom of the grid look sort of "unclosed" because of the light bottom borders. That's how the right side of the calendar would have looked if we hadn't added in the td.sat rule. Instead of creating a similar rule for the bottom of the calendar, though, let's move on to other issues and get back to the bottom of the calendar later.

Distinguishing the Months

Now that we have a grid, we should go about making its contents a little more interesting. First on the agenda is a way to make the non-July days look very different so that it's obvious they aren't part of the month in question. Again, there are a multitude of options. For example, we could just set them to be white text on a white background, making them disappear entirely. Instead, let's blue them out, so to speak.

Here's where all that classing and ID'ing really pays off. Because the non-July days are already part of the classes jun and aug, we can just write styles that apply to those classes (see Figure 3.7):

td.sat {border-right: 1px solid #BBB;}
td.jun, td.aug {background: #AAB; color: #889;

      border: 1px solid #AAB; border-right-color: #99A;}
</style>
03css07.jpg

Figure 3.7 "Blueing" out the other months helps keep the focus on July.

We're using shades of blue to go along with the styling of the calendar top, of course. By setting the text color and the background color close to each other in terms of brightness, the dates are washed out while still remaining relatively readable.

Now that we've styled the non-July days, we can go ahead and cap off the bottom of the grid. To give it a little more weight, let's set a border that's 2 pixels thick and whose color matches the background of the days in August. Fortunately, this is very easy to do because we already labeled the last row in the table (see Figure 3.8):

td.jun, td.aug {background: #AAB; color: #889;
   border: 1px solid #AAB; border-right-color: #99A;}
tr#lastweek td {border-bottom: 2px solid #AAB;}
</style>
03css08.jpg

Figure 3.8 Capping off the calendar with a thickened blue bottom border.

We also could have taken a simpler route and just applied a border to the bottom of the table itself, but that could result in less flexibility later on. In some circumstances, however, applying borders to the table element itself makes a whole lot of sense, so keep it in mind as a potential tool.

Distinguishing the Days

Just for a little extra visual flair, let's set a background on Saturdays and Sundays. Because the month is July and we already have blue and white, how about a nice light red background:

td.sat {border-right: 1px solid #BBB;}
td.sat, td.sun {background: #FDD;}
td.jun, td.aug {background: #AAB; color: #889;
   border: 1px solid #AAB; border-right-color: #99A;}

Notice that we put that rule before the one that washes out the June and August days. If we hadn't, June 30 and August 3 would both have had red backgrounds, thanks to the way our selectors are written.

So now July is nicely red, white, and blue (see Figure 3.9). What about the 4th, which is a national holiday in America? We ought to highlight it. Again, there are two choices. One would be to write a rule with the selector td#jul04, and that would work just fine. However, let's go for a more generic solution: We'll add a holiday class to that day:

<td class="jul thu holiday" id="jul04"><a href="jul04.html">4</a></td>
03css09.jpg

Figure 3.9 Highlighting the weekends in a patriotic fashion.

Now we can write a style that will apply to all holidays:

tr#lastweek td {border-bottom: 2px solid #AAB;}
td.holiday {background: #FAA;

      border-color: #BBB #FCC #FCC #BBB;}
</style>

In addition to the medium-red background, the border colors are set so that the highlighting blends in a little better with the background (see Figure 3.10).

03css10.jpg

Figure 3.10 Making Independence Day stand out.

Altering the Days of July

Now might be a good time to step back and look at the calendar as a whole. Are the individual days styled the way we want them? Should we do anything about the links versus normal text? Do we want to keep the underlining of the linked days? Do we want to change the padding of these table cells?

Let's start by assuming we don't want the linked days to be underlined. The rule to remove the underlines is very simple, but let's make sure it applies only to the links in the calendar:

<style type="text/css">
table#calendar a {text-decoration: none;}
tr#days th {color: #CCE; background-color: #224;
   font-weight: bold; text-align: center;
   padding: 1px 0.33em;}

Goodbye underlines. As a consequence of this decision, we have to come up with a way to make the links stand apart from the days that aren't linked.

There are many ways to handle such a situation, of course, but let's attack it from two directions. First, let's fade out the text of any unlinked days and additionally boldface any linked days. And, just for the heck of it, let's right-align all of the days (see Figure 3.11).

td {color: #777; text-align: right;
   border: 1px solid gray;
   border-color: #BBB #EEE #EEE #BBB;}
td.sat {border-right: 1px solid #BBB;}
td a {font-weight: bold;}
td.sat, td.sun {background: #FDD;}
03css11.jpg

Figure 3.11 The linked days now stand out much more clearly, and all the days have shifted to the right.

The links could stand to be even more obvious, so let's change their color. A navy blue would be nice (not to mention would fit in with the rest of the calendar), and we could set visited links to be purple. In addition, let's make the background of the links a medium yellow when the user hovers over a link.

td a {font-weight: bold;}
table#calendar a:link {color: navy;}

   table#calendar a:visited {color: purple;}

   table#calendar a:hover {background: #FF6;}
td.sat, td.sun {background: #FDD;}

Unfortunately, the hover effect will only appear behind the actual text of the link, not the entire table cell. There are a number of ways to correct this problem, but most of them use highly complicated JavaScript in an attempt to support Navigator 4.x. Let's use the much simpler CSS way of making the links block-level elements. That way, they'll fill up the whole cell and neatly solve our problem (see Figure 3.12).

td.sat {border-right: 1px solid #BBB;}
td a {font-weight: bold; display: block; margin: 0;}
td a:link {color: navy;}
03css12.jpg

Figure 3.12 The linked days now stand out much more clearly.

Making Today a Major Highlight

With everything else basically done, now we just need to highlight the current date. For testing purposes, we'll assume it's July 16. Let's go with a yellow background and a black border to really make today obvious (see Figure 3.13):

td.holiday {background: #FAA; border-color: #BBB #FCC #FCC #BBB;}
td#jul16 {background-color: yellow; border: 1px solid black;}
</style>

03css13.jpg

Figure 3.13 Highlighting the current date.

Now we see why it was a good idea to set all four borders for every cell. Had we not done so, setting the border on the current date could have thrown off the layout of the table due to our setting all four borders for the current date.

Placing the Calendar in an Existing Document

Because we've been styling a document that contains only the calendar, we've been able to get a little lazy about our selectors. Consider the following rule from our style sheet, for example:

td {color: #777; text-align: right;
   border: 1px solid gray;
   border-color: #BBB #EEE #EEE #BBB;}

This works fine in our test document, but imagine applying the rule to a page that had the calendar placed somewhere on it. We don't want all of the text in every single table cell in the whole page to be grayed out and right aligned!

There is really only one fix, but fortunately it's a simple one. We need to add the string table#calendar at the front of any selector that doesn't already contain it. Listing 3.1 shows the changes this causes in the context of the entire style sheet. It's necessary to make all of these changes because, if we don't, the differences in specificity could cause the styles to change as rules begin to override each other in unexpected ways.

Example 3.1. The Full Style Sheet, Showing Altered Selectors

<style type="text/css">
table#calendar a {text-decoration: none;}
table#calendar tr#days th {color: #CCE; background-color: #224;
   font-weight: bold; text-align: center;
   padding: 1px 0.33em;}
table#calendar tr#title th {background: #AAC; color: black;
   border: 1px solid #242; font-size: 120%;}
table#calendar td {color: #777; text-align: right;
   border: 1px solid gray;
   border-color: #BBB #EEE #EEE #BBB;}
table#calendar td.sat {border-right: 1px solid #BBB;}
table#calendar a {font-weight: bold; display: block; margin: 0;}
table#calendar a:link {color: navy;}
table#calendar a:visited {color: purple;}
table#calendar a:hover {background: #FF6;}
table#calendar td.sat, table#calendar td.sun {background: #FDD;}
table#calendar td.jun, table#calendar td.aug {
   background: #AAB; color: #889;
   border: 1px solid #AAB; border-right-color: #99A;}
table#calendar tr#lastweek td {border-bottom: 2px solid #AAB;}
table#calendar td.holiday {background: #FAA;
   border-color: #BBB #FCC #FCC #BBB;}
table#calendar td#jul16 {background-color: yellow;
   border: 1px solid black;}
</style>

Looking at the resulting rules, it might have been better to give the table an id value of cal or maybe smcal, just to keep the selectors shorter. Nevertheless, these kinds of selectors are necessary when you're styling just one portion of a document. In this case, the addition of table#calendar keeps the calendar styles confined to just that piece of the document.

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