Newbie alert, this is my first post (other than my intro post), so please go easy.
I stumbled across the problem (outlined below) and was hoping someone could shed some light. If you think that my markup/CSS could be improved, please advise, it would be greatly appreciated.
Problem Description:
IE\Win not displaying CSS declarations correctly when there is any kind of text prior to the opening <html> tag.
In the example code below I am floating two block elements side-by-side inside a table column and the content is centered vertically. To do this I am using the display: table-cell trick. When there is text before the <html> tag this trick does not work, however by removing the text before the <html> tag, it works. Also noticed that the table border turns #000 when there is text before the <html> tag.
I ran into this problem because I had PHP outputting HTML comments. The problem does not occur on FF\Win, FF\Mac, SF\Mac. The problem is easily resolved by simply removing any text prior <html> tag, but as a web newbie I am interested in what is actually happening here?
Example markup:
<!--Comment-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Vertically Align content nested in block/inline elements</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
color: #7F7F7F;
font-family: verdana,arial,helvetica,san-serif;
}
table {
border: 1px solid #000000;
border-collapse: collapse;
margin: 0;
padding: 0;
table-layout: fixed;
width: 0;
}
table tr th,
table tr td {
border: 1px solid #CFCFCF;
overflow: hidden;
width: 12em;
}
table tr td {
height: 4em;
}
table tr td div {
background-color: #FFFFCF;
height: 100%;
overflow: hidden;
width: 100%;
}
table tr td div.left {
float: left;
width: 2em;
}
table tr td div.right {
float: right;
width: 10em;
}
table tr td div div {
display: table; /* To allow nested element to use vertical-align */
}
table tr td div.left div {
background-color: #E7FFDF;
}
table tr td div div span {
display: table-cell; /* enable vertical-align */
vertical-align: middle;
}
</style>
</head>
<body>
<table summary="Testing table for vertical align">
<caption>Vertical Align Test</caption>
<tr>
<th scope="col">row 1</th>
<th scope="col">row 2</th>
<th scope="col">row 3</th>
<th scope="col">row 4</th>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>
<div class="left"><div><span>lefttext</span></div></div>
<div class="right"><div><span>righttext_longtextthatwilloverflow</span></div></div>
</td>
</tr>
</table>
</body>
</html>
To test this for yourself simply add/remove “<!–Comment–>” from the beginning of the document.
Note: The problem does not occur if there is newlines, only if there is visible text.