wac
10-27-2006, 06:25 PM
This is a bit too subtle for me. I've got a web page with a fixed header, scrolling body table (a single table, not a composite), which works fine in IE with
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"-->
However, we've got a company mandate to use
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
and now the header is not fixed in IE. Firefox, of course works without problems. I used a CSS hack I got from http://www.alistapart.com/articles/zebratables/ a long time ago. Can't pretend to understand it, but unfortunately I need to now.
==CSS==
/* this is the only style required by CSS2 compliant browsers to make the table body scrollable
* while the header remains fixed
*/
.scroll_table > tbody
{
overflow: auto ;
overflow-x: hidden ;
height:100% ;
}
/* pretty stuff */
.scroll_table
{
border: 2px outset activeborder ;
width: 100% ;
}
.scroll_table thead th
{
background-color: activeborder;
border-left: 2px groove activeborder;
font-weight: normal;
padding: 2px ;
text-align: left
}
.scroll_table td
{
border-left: 2px outset activeborder ;
padding: 2px ;
}
/* fix issues with vertical scrollbar obscuring content in non IE browsers */
.scroll_table tbody > tr > td
{
padding-right: 15px ;
}
===IE specific CSS===
.scroll_container
{
border: 2px outset activeborder ;
overflow: inherit ;
overflow-y: auto;
/*
* (IE quirk)
* when width:100% is used, div is slightly wider than page,
* causing horizontal scroll bar. Don't know why.
*/
width: 98% ;
}
.scroll_table
{
border: none ;
}
.scroll_table thead tr
{
position: relative
}
.scroll_table thead th
{
position: relative
}
===== sample table =====
<!--[if lt IE 7]>
<div class="scroll_container" style='height:150px;width:98%' >
<![endif] -->
<table class="scroll_table" tabindex='0' cellpadding="0" cellspacing="0" width="100%" >
<thead >
<tr><th colspan="2" style='border-bottom:2px groove activeborder'>Span 2</th><th style='border-bottom:2px groove activeborder'>Span 1</th></tr>
<tr>
<th width="50%" style='border-left:none'>Tree</th>
<th width="20%" >Col 1</th>
<th width="30%" >Col 2</th>
</tr>
</thead>
<![if gt IE 100]>
<%-- only non-IE (eg firefox) --%>
<tbody style='height:150px'>
<![endif]>
<!--[if lt IE 7]>
<tbody >
<![endif] -->
<tr id='test1' ><TD >stuff0</TD><TD >col 2</TD><td >col 3</TD></tr>
<tr id='test1' ><TD >stuff1</TD><TD >col 2</TD><td >col 3</TD></tr>
<tr id='test2' ><TD >stuff1</TD><TD>col 2</TD><td>long text 0 1 2 3 4 5 6 7 8 9 q w e r t y u i o p</td></tr>
<tr id='test3' ><td >stuff2</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test4' ><td style="padding-left:40px">child 21</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test5'><td > stuff 22 with long text a a a a a a a a a a a a a a a a a</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test6' ><td >stuff23</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test7' ><td >stuff3</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test8' ><td >stuff2 with long text</TD><TD>col 2</TD><td>long text 0 1 2 3 4 5 6 7 8 9 q w e r t y u i o p</TD></tr>
<tr id='test9' ><td >stuff3</TD><TD>col 2</TD><td>col 3</TD></tr>
</tbody>
</table>
<!--[if lt IE 7]>
</div>
<![endif] -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"-->
However, we've got a company mandate to use
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
and now the header is not fixed in IE. Firefox, of course works without problems. I used a CSS hack I got from http://www.alistapart.com/articles/zebratables/ a long time ago. Can't pretend to understand it, but unfortunately I need to now.
==CSS==
/* this is the only style required by CSS2 compliant browsers to make the table body scrollable
* while the header remains fixed
*/
.scroll_table > tbody
{
overflow: auto ;
overflow-x: hidden ;
height:100% ;
}
/* pretty stuff */
.scroll_table
{
border: 2px outset activeborder ;
width: 100% ;
}
.scroll_table thead th
{
background-color: activeborder;
border-left: 2px groove activeborder;
font-weight: normal;
padding: 2px ;
text-align: left
}
.scroll_table td
{
border-left: 2px outset activeborder ;
padding: 2px ;
}
/* fix issues with vertical scrollbar obscuring content in non IE browsers */
.scroll_table tbody > tr > td
{
padding-right: 15px ;
}
===IE specific CSS===
.scroll_container
{
border: 2px outset activeborder ;
overflow: inherit ;
overflow-y: auto;
/*
* (IE quirk)
* when width:100% is used, div is slightly wider than page,
* causing horizontal scroll bar. Don't know why.
*/
width: 98% ;
}
.scroll_table
{
border: none ;
}
.scroll_table thead tr
{
position: relative
}
.scroll_table thead th
{
position: relative
}
===== sample table =====
<!--[if lt IE 7]>
<div class="scroll_container" style='height:150px;width:98%' >
<![endif] -->
<table class="scroll_table" tabindex='0' cellpadding="0" cellspacing="0" width="100%" >
<thead >
<tr><th colspan="2" style='border-bottom:2px groove activeborder'>Span 2</th><th style='border-bottom:2px groove activeborder'>Span 1</th></tr>
<tr>
<th width="50%" style='border-left:none'>Tree</th>
<th width="20%" >Col 1</th>
<th width="30%" >Col 2</th>
</tr>
</thead>
<![if gt IE 100]>
<%-- only non-IE (eg firefox) --%>
<tbody style='height:150px'>
<![endif]>
<!--[if lt IE 7]>
<tbody >
<![endif] -->
<tr id='test1' ><TD >stuff0</TD><TD >col 2</TD><td >col 3</TD></tr>
<tr id='test1' ><TD >stuff1</TD><TD >col 2</TD><td >col 3</TD></tr>
<tr id='test2' ><TD >stuff1</TD><TD>col 2</TD><td>long text 0 1 2 3 4 5 6 7 8 9 q w e r t y u i o p</td></tr>
<tr id='test3' ><td >stuff2</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test4' ><td style="padding-left:40px">child 21</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test5'><td > stuff 22 with long text a a a a a a a a a a a a a a a a a</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test6' ><td >stuff23</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test7' ><td >stuff3</TD><TD>col 2</TD><td>col 3</TD></tr>
<tr id='test8' ><td >stuff2 with long text</TD><TD>col 2</TD><td>long text 0 1 2 3 4 5 6 7 8 9 q w e r t y u i o p</TD></tr>
<tr id='test9' ><td >stuff3</TD><TD>col 2</TD><td>col 3</TD></tr>
</tbody>
</table>
<!--[if lt IE 7]>
</div>
<![endif] -->