Great
for organization,
calendars enable us to schedule lunches, remember birthdays, and plan
honeymoons. As designers, we can think of all those months, dates, and
appointments as tabular data.
If you display your calendar as an
HTML table, chances are the table looks rather
plain, and if it contains numerous events then it probably looks somewhat
convoluted as well. In this design, we use CSS to create a calendar that is more
legible than what you could create using vanilla HTML.
First, take a look at Figure 6-7, which shows the markup for the
calendar without styles.
Next, look at the markup itself to see how it's set up. As you
learned in Section 6.1, the
cellspacing attribute needs to be
set in the
table element:
<table cellspacing="0">
Now, set the first three rows of table headers, th,
containing the year, month, and days, in their own rows within their own table
headers:
<tr>
<th colspan="7" id="year">
<a href="year.html?previous"><</a> 2000 <a
href="year.html?next">></a>
</th>
</tr>
<tr>
<th colspan="7" id="month">
<a href="month.html?previous"><</a> October <a
href="month.html?next">></a>
</th>
</tr>
<tr id="days">
<th>Sunday</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday </th>
<th>Saturday</th>
</tr>
The first date is October 1, which in this calendar falls on a
Sunday. To signify that Sundays and Saturdays are days of the weekend, use a
class selector in the td element.
In each date of the month there is a link on the date itself
(which would, in theory, take the user to a detailed listing of the day) as well
as a link to add more events to the day. Wrap these two links in a div
element so that when new events are added there is a clear division between the
two sections in the table cell:
<tr>
<td class="weekend">
<div>
<a href="1.html" class="date">1</a>
<a href="add.html" class="addevent">+</a>
</div>
</td>
The next date, October 2, has an event listed. The event is
marked up as a link and placed below the div containing the date and
the addevent links (because October 2 is a weekday, the
weekend class isn't applied to the td element):
<td>
<div>
<a href="2.html" class="date">2</a>
<a href="add.html" class="addevent">+</a>
</div>
<a href="16.html?id=1" class="event">Regular City
Commission meeting agenda</a>
</td>
The rest of the markup follows a similar structure:
<td>
<div>
<a href="3.html" class="date">3</a>
<a href="add.html" class="addevent">+</a>
</div>
</td>
<td>
<div>
<a href="4.html" class="date">4</a>
<a href="add.html" class="addevent">+</a>
</div>
</td>
<td>
<div>
<a href="5.html" class="date">5</a>
<a href="add.html" class="addevent">+</a>
</div>
<a href="5.html?id=1" class="event">Dad's birthday</a>
</td>
<td>
<div>
<a href="6.html" class="date">6</a>
<a href="add.html" class="addevent">+</a>
</div>
</td>
<td class="weekend">