Really, to explain how to do this would take quite a while. I can give you some general pointers, however...
Basically, in the example you provided, the authors of that calendar used absolutely-positioned divs that layed over the calendar. If you open up Firebug in Firefox and 'inspect element' one of the spans, and then watch the element as you re-size the browser, you'll notice that they turn yellow. This is because JavaScript is actively re-sizing the elements when items are added or when the page is re-sized. I tried to do something similar to this for a while and eventually gave up due to it's complexity and unnecessary cumbersomeness.
What I eventually did was go against my strong anti-table mentality and used the colspan
attribute of <td>
elements in the table itself. Each line of events is a <tr>
and each event is a <td>
. Since <td>
s can span multiple "columns" using the colspan
attribute.
So, to break it down...
The calendar is a <div>
. Each week is another 100%-width <div>
that contains two tables:
- The first table just contains the cell borders, to give the calendar look.
- The second contains the the day numbers, events, etc...
In the second table, the first row has 7 columns (1 for each day of the week). All the tertiary rows only have the number of rows necessary to show their events. So, a week that only has 1 event, on, say, Thursday which spans 2 days (from Thurs. to Fri.) would have 6 columns:
That row would be something like:
<tr>
<td class="no-event"></td> <!-- Sunday -->
<td class="no-event"></td> <!-- Monday -->
<td class="no-event"></td> <!-- Tuesday -->
<td class="no-event"></td> <!-- Wednesday -->
<td class="no-event" colspan="2"> <!-- Thursday through Friday -->
<div class="some-styling-class">Vacation to Orlando!</div>
</td>
<td class="no-event"></td> <!-- Saturday -->
</tr>
Notice how there are only 6 columns... (since the event with colspan="2"
takes up 2 columns worth).
Each table is positioned fixedly to the parent 'week' div... the first one has a lower z-index so that the second table (events, etc...) will show up on top and span over the calendar cell borders.
This is actually what Google uses to construct their Google Calendars. It's actually quite elegant, easy to work with, and there's little-to-no crazy javascript to write. The most challenging thing is to wrap an event from, say, Thursday on one week to, say, Wednesday on another week (since you have to make n number of colspans <td>
's depending on the amount of weeks spanned in the visible calendar space).
So, my suggestion would actually be to investigate Google's G-Cal table structure and see what you can extrapolate from that. The easy way is to just copy the entire HTML from it using Firebug and paste it into an editor and then just toy around until you understand how it works.
I hope what I've shown helps. Good luck dude.