Welcome to the sixth part of an eight-part article series that shows you how to build a web page calendar. Up to now we've mostly been dealing with calculating and displaying the months. In this part of the series I talk about the layout of the calendar, and I introduce a new function that will show an entire year at a time.
Showing a Full Year with a Web Page Calendar (Page 1 of 4 )
Layout of Calendar for the Year
We have one main DIV element. We put four of our month calendars in one row in the DIV element. Remember what I said about the IDs in the previous part of the series. Each month's calendar will be in its DIV element as it was for the single month calendar.
The IDs for the Input Text Control for the first month (January) are IA1 and IA2; those for the second month are IB1 and IB2; those for the third month are IC1 and IC2; etc. As we said, A represents January, B represents February, C represents March, and so on.
It is the single month calendar format that has been repeated for the twelve calendars. There is a small change though: in order to avoid layout problems, the Input Text elements are now part of the calendar table. A row has been added before the other rows in the calendar table. This added row has only one cell with the colspan attribute of "colspan='7'". This cell has the Input Text elements. This is the row for January:
The other months have similar rows which change only the IDs of the Input Text controls. Note that the only table cell here does not have an ID. It does not need to have one because it will not be addressed. Remember that the table cells that have the abbreviations for the days of the week also do not have IDs. They are not addressed.
Three CSS statements are added. The added statements are:
The first statement above is for the main DIV element. This is the DIV element that contains the other DIV elements for the calendars. The ID of this DIV element is YR. The style for this DIV element is the same as that for the DIV element for the single calendar.
The DIV elements for the calendars of the twelve months now have a different style. These DIV elements are grouped into a class called CalM. The second statement above defines their style.
A DIV element is a block level element, meaning that it has an inherent BR element in front and after it. In order to neutralize the effect of the inherent BR elements, you have to give the DIV element an "inline" value for its CSS display property. In that way, consecutive DIV elements will appear in a line (horizontally).
We want four DIV elements for the calendar months to appear in one line. There are 12 months in a year. This means we would have three rows of four months each for a yearly calendar. So we give the value "inline" for the CSS display property for the DIV elements of the CalM class (see the second statement above). To have the three rows, after the first set of four, we put the <br /> element. After the next set of four, we put the <br /> element. The last set of four DIV elements does not need the <br /> element, since it is at the bottom.
With what we have said so far, you should see a yearly calendar made up of three-month rows and four-month columns, if you click the appropriate button. Well, with my browser that did not work. The reason is that the TABLE element also has a line break element in front of and after it. The solution was to put all the TABLE elements for the yearly calendar into a class called Inl (third statement above) and give the elements the value of "inline" for the CSS display property. I will give you the complete code in a zip format file at the end of the series.