HTML表格中的PHP变量在Chrome,Firefox和Safari中表现良好,但在IE 8中表现不佳

时间:2011-06-07 23:10:52

标签: html css internet-explorer cross-browser

下表在Chrome,Firefox和Safari中表现出色。它的左侧部分显示如下:

enter image description here

但是,在Internet Explorer 8中,左侧部分有时会显示如下:enter image description here

在IE8中,通过简短评论,只显示变量$row["username"]的顶部,即屏幕截图中的“admin”。我怎样才能使IE8在这种情况下显示完整的$row["username"]

提前致谢,

约翰

源代码:

echo "<table class=\"commentecho\">";
$count = 1;
while ($row = mysql_fetch_array($result)) { 
    $dt1 = new DateTime($row["datecommented"], $tzFrom1);  
    $dt1->setTimezone($tzTo1);
    echo '<tr>';
    echo '<td style="border-left:2px solid #004993; border-bottom:2px solid #004993; border-top:2px solid #004993;" rowspan="3" class="commentnamecount">'.$count++.'</td>';
    echo '<td style="background: #CAE1FF; border-top:2px solid #004993;" class="commentname2user"><a href="http://www...com/.../index.php?profile='.$row["username"].'">'.$row["username"].'</a></td>';
    echo '<td style="border-right:2px solid #004993; border-bottom:2px solid #004993; border-top:2px solid #004993;" rowspan="3" class="commentname1" id="comment-' . $row["commentid"] . '">'.stripslashes($row["comment"]).'</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td style="background: #CAE1FF;" class="commentname2">'.$dt1->format('F j, Y').'</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td style="background: #CAE1FF; border-bottom:2px solid #004993;" class="commentname2a">'.$dt1->format('g:i a').'</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="commentname2a"></td>';
    echo '</tr>';
    }
echo "</table>";

CSS:

table.commentecho {
    margin-top: 20px;
    margin-left: 30px;
    text-align: left;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: normal;
    font-size: 14px;
    color: #000000;
    width: 450px;
    table-layout:fixed;
    background-color: #FFFFFF;
    border: 2px #FFFFFF;
    border-collapse: collapse;
    border-spacing: 0px;
    padding: 0px;
    text-decoration: none;
    vertical-align: text-bottom;    

}

table.commentecho td {
   border: 0px solid #fff;  
   text-align: left; 
   height: 20px;


}

table.commentecho td a{
   padding: 2px;
   color: #004284;
   text-decoration: none;
   font-weight:bold;
   height: 20px;
}

table.commentecho td a:hover{
   background-color: #004284;
   padding: 2px;
   color: #FFFFFF;
   text-decoration: none;
   font-weight:bold;
   height: 20px;
}

.commentnamecount { width: 50px;
            font-family:Arial, Helvetica, sans-serif;
            font-size: 25px;   
            overflow:hidden !important;
            color: #004993;
            font-weight: bold;
            display:table-cell;   
            vertical-align: top;
            padding-bottom: 0px;
            padding-left: 5px;
            padding-top: 2px;

}


.commentname2user { width: 120px;
            color: #000000;
            font-family:Arial, Helvetica, sans-serif;
            font-size: 14px;
            font-weight: normal;
            height: 50px;
            padding-top:5px;
            padding-left: 5px;
            padding-bottom: 10px;
            vertical-align: top;

}

.commentname1 { 
            line-height: 170%;
            width: 410px;
            font-family: Georgia, "Times New Roman", Times, serif;
            overflow:hidden !important;
            color: #000000;
            padding-bottom: 30px;
            padding-left: 10px;
            vertical-align: top;
}


.commentname2 { width: 120px;
            color: #000000;
            font-family:Arial, Helvetica, sans-serif;
            font-size: 11px;
            font-weight: normal;
            height: 20px;
            padding-top:0px;
            padding-left: 5px;
            padding-bottom: 0px;
            vertical-align: top;

}

.commentname2 a{ width: 120px;
            color: #004284;
            font-family:Arial, Helvetica, sans-serif;
            font-size: 14px;
            font-weight: bold;
            height: 20px;
            padding-top:0px;
            padding-bottom: 10px;
            vertical-align: top;

}

.commentname2 a:hover{ width: 120px;
            color: #004284;
            font-family:Arial, Helvetica, sans-serif;
            font-size: 14px;
            font-weight: bold;
            text-decoration: underline;
            height: 20px;
            padding-top:0px;
            padding-bottom: 0px;
            vertical-align: top;

}

.commentname2a { width: 160px;
            overflow:hidden !important;
            color: #000000;
            font-family:Arial, Helvetica, sans-serif;
            font-size: 11px;
            font-weight: normal;
            height: 40px;
            padding-top:0px;
            padding-left: 5px;
            padding-bottom: 30px;
            vertical-align: top;

}   

3 个答案:

答案 0 :(得分:2)

嗯,你确实要求链接只有这么高:

table.commentecho td a {
    height: 20px;
}

诀窍是,这应该不起作用,并且在大多数浏览器中都不行:根据CSS标准,height显式不适用于<a>等内联元素。然而,在IE的Quirks Mode它无论如何都会这样做。所以:

  • 删除无效的height:属性
  • 确保使用标准模式DOCTYPE声明为您的页面提供服务。你不希望Quirks Mode充满了令人讨厌的遗留兼容性错误。

还要记住在将数据字符串模板化为HTML时使用htmlspecialchars(),否则您将遇到跨站点脚本漏洞。 stripslashes()不做这项工作,几乎肯定是一个错误。

答案 1 :(得分:0)

它看起来像一个行高问题。尝试将实际像素/设置值放在.commentname2user和.commentname1的行高上

答案 2 :(得分:0)

我对你的php代码和你的css做了一些安排,但这在两个浏览器中看起来都差不多,希望这有帮助......

PHP代码:

echo '<table class="comments" cellspacing="0">';
$count = 1;
while ($row = mysql_fetch_array($result)) { 
    $dt1 = new DateTime($row["datecommented"], $tzFrom1);  
    $dt1->setTimezone($tzTo1);
    echo '<tr>';
    echo '<td class="comment-count">'.$count++.'</td>';
    echo '<td class="comment-user">';
    echo '<a href="http://www...com/.../index.php?profile='.$row["username"].'">'.$row["username"].'</a>'
    echo '<br/><span class="comment-date">'.$dt1->format('F j, Y').'</span><br/>';
    echo '<span class="comment-hour">'.$dt1->format('F j, Y').'</span>';
    echo '</td>';
    echo '<td class="comment-text" id="comment-' . $row["commentid"] . '">'.stripslashes($row["comment"]).'</td>';
    echo '</tr>';
    }
echo "</table>";

你的CSS:

table.comments{
    margin: 20px 0 30px;
    width: 450px;
}
table.comments td{
    vertical-align:top;
    border: solid #004993;
    border-width:2px 0 2px 0;
}
table.comments td.comment-count{
    border-left: 2px solid #004993;
    width: 50px;
    font:bold 25px Arial, Helvetica, sans-serif;
    color: #004993;
    vertical-align: top;
    padding:2px 0 0 5px;
}
table.comments td.comment-user{width:120px;background-color:#CAE1FF;padding: 5px;}
table.comments td.comment-user a{
    font:bold 14px/20px Arial, Helvetica, sans-serif; 
    text-decoration:none;
    color: #004284;
    padding:2px;
}
table.comments td.comment-user a:hover{background-color: #004284; color:#CAE1FF;}
table.comments td.comment-user span.comment-date, span.comment-hour{
    font:11px Arial, Helvetica, sans-serif;
}
table.comments td.comment-text{
    border-right: 2px solid #004993;
    width: 410px;
    font: normal 14px/20px Georgia, "Times New Roman", Times, serif;
    padding-left: 10px;
}