CSS - Test Your CSS Skills Number 22

CSS - Test Your CSS Skills Number 22 : Quiz now ended - Solution posted in post #69

[SIZE=4][SIZE=2]Hope you enjoyed your break from the quizzes but now its time to turn the tables.:slight_smile:

I love it when someone tells me something can’t be done with CSS because 99% of the time it can be done if you think about it hard enough. This quiz is no exception and you once again have to achieve what everyone still says is impossible to do in a cross browser way.

Your mission is to create a data table where the header of the table remains fixed while the data in the table can scroll. This is especially useful for long tables as the header row always stays visible and above the data it refers to.

If you don’t know what I mean then take a look at the attachment which clearly shows what I’m asking for.

Are you back yet?.. Then we’ll continue…

Although I have said that this is impossible to do in a cross browser way is is actually very easy to do in Firefox. All you need do is set the tbody element to overflow:scroll and give it a height and then you get scrolling data with a fixed header.

Unfortunately Firefox is the only browser that supports this and all other browsers fail (although some have limited support).

Therefore your task is to find another method that will work in ie6 - 8, Firefox 2+, safari3 and opera 9.5+ and look more or less the same in each.

I will allow one or 2 (maximum 2) little hacks for IE just to tidy things up but their should be no real forking of the code and the same code should work in all browsers.

No scripting allowed and the CSS and html should be valid. I used css2.1 and 1 css3 rule just to tidy things up but wasn’t really necessary.

More Rules:

Only one table to be used. You can’t put the header data into one table and the data in another table.

The header cells must match the data cells width and therefore would be suitable for dynamic data. This means you can’t simply set a fixed or percentage widths for the header cells and for the data cells to make them match up or use hundreds of margins to push everything into place. It must more or less be automatic.

Don’t use table-layout:fixed to make the cells even as that would be cheating for this quiz.

The table should be a fluid width and expand and contract within reasonable limits but I won’t mind if it breaks at smaller sizes or when the data is completely squashed. As mentioned above the header cells and data cells will stretch together.

No scripting.

I will provide a basic html because I’m feeling generous but you can change this to suit. I will mention that my examples seen in the screenshot actually need no changes to the table html at all. However feel free to change the html and css as you wish as you may find a better method than mine.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
p {margin:0 0 1em}
table p {margin :0}
table {
    width:100%;
    border-collapse:collapse;
}
td {
    border:1px solid #000;
    text-align:center;
    background:yellow;
}
th {
    font-weight:bold;
    border:1px solid #000;
    background:#ffffcc
}
</style>
<!--[if lte IE 7]>
<style type="text/css">

</style>
<![endif]-->
</head>
<body>
<h1>Table with fixed header in IE6 - 8, Firefox 2.+, Safari 3 and Opera 9.5+</h1>
<p>Notes: The header is part of the same table and not a separate table on top. The width of the table cells or header cells is not defined and will match whatever content is in the cells. The table can be a fluid length and will resize within reasonable limits accordingly.</p>
<table id="data" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th><p>Jan</p></th>
            <th><p>Feb</p></th>
            <th><p>Mar</p></th>
            <th><p>Apr</p></th>
            <th><p>May</p></th>
            <th><p>Jun</p></th>
            <th><p>Jul</p></th>
            <th><p>Aug</p></th>
            <th><p>September</p></th>
            <th><p>Oct</p></th>
            <th><p>Nov</p></th>
            <th class="last"><p>Dec</p></th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th><p>Jan</p></th>
            <th><p>Feb</p></th>
            <th><p>Mar</p></th>
            <th><p>Apr</p></th>
            <th><p>May</p></th>
            <th><p>Jun</p></th>
            <th><p>Jul</p></th>
            <th><p>Aug</p></th>
            <th><p>September</p></th>
            <th><p>Oct</p></th>
            <th><p>Nov</p></th>
            <th class="last"><p>Dec</p></th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td>1</td>
            <td>3</td>
            <td>5</td>
            <td>1</td>
            <td>1</td>
            <td>3</td>
            <td>1</td>
            <td>5</td>
            <td>7</td>
            <td>1</td>
            <td>1</td>
            <td class="last">3</td>
        </tr>
        <tr>
            <td>1</td>
            <td>3</td>
            <td>5</td>
            <td>1</td>
            <td>1</td>
            <td>3</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>3 more data</td>
            <td>5</td>
            <td class="last">7</td>
        </tr>
        <tr>
            <td>2</td>
            <td>4</td>
            <td>6</td>
            <td>1</td>
            <td>1</td>
            <td>3</td>
            <td>1</td>
            <td>23</td>
            <td>4</td>
            <td>1</td>
            <td>6</td>
            <td class="last">6</td>
        </tr>
        <tr>
            <td>1</td>
            <td>1</td>
            <td>6</td>
            <td>1</td>
            <td>4</td>
            <td>7</td>
            <td>1</td>
            <td>7</td>
            <td>1</td>
            <td>1</td>
            <td>3</td>
            <td class="last">6</td>
        </tr>
        <tr>
            <td>2</td>
            <td>3 with more data</td>
            <td>2</td>
            <td>3</td>
            <td>3</td>
            <td>3</td>
            <td>8</td>
            <td>1</td>
            <td>1</td>
            <td>2</td>
            <td>8</td>
            <td class="last">6</td>
        </tr>
        <tr>
            <td>6</td>
            <td>4</td>
            <td>4</td>
            <td>4</td>
            <td>2</td>
            <td>9</td>
            <td>4</td>
            <td>4</td>
            <td>6</td>
            <td>1</td>
            <td>1</td>
            <td class="last">3</td>
        </tr>
        <tr>
            <td>1</td>
            <td>1</td>
            <td>3</td>
            <td>7</td>
            <td>4</td>
            <td>5</td>
            <td>5</td>
            <td>2</td>
            <td>0</td>
            <td>3</td>
            <td>23</td>
            <td class="last">6</td>
        </tr>
        <tr>
            <td>7</td>
            <td>4</td>
            <td>2</td>
            <td>67</td>
            <td>2</td>
            <td>1</td>
            <td>1</td>
            <td>3</td>
            <td>1</td>
            <td>4</td>
            <td>4</td>
            <td class="last">4</td>
        </tr>
        <tr>
            <td>2</td>
            <td>4</td>
            <td>3</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>3</td>
            <td>2</td>
            <td>2</td>
            <td>5</td>
            <td>65</td>
            <td class="last">4</td>
        </tr>
        <tr>
            <td>2</td>
            <td>4</td>
            <td>4</td>
            <td>1</td>
            <td>2</td>
            <td>13</td>
            <td>6</td>
            <td>1</td>
            <td>1</td>
            <td>3</td>
            <td>7</td>
            <td class="last">4</td>
        </tr>
    </tbody>
</table>
</body>
</html>


Remember that you must make sure that it works before you send it to me :slight_smile:

Do not post your answers here but PM them to me so that others can have a go without seeing your answers.

Any questions just ask and remember this is just for fun :slight_smile:

[/SIZE][/SIZE]Solutions to the quiz will be posted at the end of the week (or longer) depending on how it goes :slight_smile:

Have fun .

Paul

PS. : In case you missed the other tests you can find them here:
test 1: [URL=“http://www.sitepoint.com/forums/showthread.php?t=169710”]test 2: [URL=“http://www.sitepoint.com/forums/showthread.php?t=170190”]test 3: [URL=“http://www.sitepoint.com/forums/showthread.php?t=171221”]test 4: [URL=“http://www.sitepoint.com/forums/showthread.php?t=172472”]test 5: [URL=“http://www.sitepoint.com/forums/showthread.php?t=173786&highlight=test+css+skills”]test 6: [URL=“http://www.sitepoint.com/forums/showthread.php?p=3216244#post3216244”]test 7: [URL=“http://www.sitepoint.com/forums/showthread.php?p=3235664#post3235664”]test 8: [URL=“http://www.sitepoint.com/forums/showthread.php?p=4108145#post4108145”]test9: [URL=“http://www.sitepoint.com/forums/showthread.php?p=4119063#post4119063”]test10: [URL=“http://www.sitepoint.com/forums/showthread.php?t=595943”]test11: [URL=“http://www.sitepoint.com/forums/showthread.php?t=597256”]test12:
test13: [URL=“http://www.sitepoint.com/forums/showthread.php?t=600332”]test 14: [URL=“http://www.sitepoint.com/forums/showthread.php?t=601564”]test 15: [URL=“http://www.sitepoint.com/forums/showthread.php?t=602808”]test 16: [URL=“http://www.sitepoint.com/forums/showthread.php?t=604228”]test 17:[URL=“http://www.sitepoint.com/forums/showthread.php?t=605819”]test18 [URL=“http://www.sitepoint.com/forums/showthread.php?p=4218017#post4218017”]test 19:
test 20:
test 21:

hahahahhaa, this is what you call Saturday morning??!

edit:
quiz looks promising, im not sure ill be able to try it right away, -workload.

Thanks for this!

I’m so swamped with workload that I won’t manage this week, bleh. :confused:
But I’ll try next weekend, if the quiz is still open by then. :slight_smile:

I’m in.

I’m very close…ggetting IE6 to work was actually easiest…cmon FF!

Edit:

Working everywhere but IE…

This is a good quiz Paul.

Edit:

Very hard…

well, i tried a little of the quiz in my coffee break, and i have to say, this would come it handy for a couple of projects already!

p.s. gotta love the forums where everyone keeps going “no you can’t, its impossible…xD”

Gah hard quiz. Scrolling is good…dang thead. This can be done so easily if I could restructure…

Ok Firefox is completely done…

No only the header stays fixed.

The footer just scrolls into view at the end of the data as shown on the attachment.

Yea that’s what I mean. Is it ok for us to have both as stickied?

Yea that’s what I mean. Is it ok for us to have both as stickied?

As long as you can make it work in all the browsers mentioned then go ahead.

Remember you must still use only one table and not three:)

I’m not ;).

Good Quiz

not easy xD

Seems I made this one too hard for you all :slight_smile:

or maybe we just don’t like working with tables xD
or maybe we are full of work
or maybe we are just lazy
or maybe we will do it soon

lol :slight_smile:

Lol it’s too hard for me…

Edit-Paul what happens when you vertically resize the window…

Sent in a quasi-working solution, as I don’t have time to iron out all the wrinkles. :slight_smile:

Thanks for the entry Tommy that was more or less the answer I was looking for :slight_smile:

Thanks for taking part and getting this going;)

Nothing strange happens when you vertically resize the window :slight_smile:

The header isn’t fixed using fixed positioning if that’s what you were hinting at :slight_smile: