2011-01-24 190 views
0

我想知道我在这段代码上犯的错误,但是我不能。在Firefox和IE上运行良好,但在Chrome中,内部单元不像代码似的那样居中。谷歌浏览器上的表格格式(纯html)

<table cellpadding="0" cellspacing="0" style="width: 100%"> 
    <tr> 
     <td rowspan="7"></td> 
     <td style="width: 600px; height: 100px;">&nbsp;</td> 
     <td rowspan="7"></td> 
    </tr> 
    <tr> 
     <td class="style1" valign="top"><?php echo($title); ?></td> 
    </tr> 
    <tr> 
     <td class="style2" valign="top"><?php echo($subtitle); ?></td> 
    </tr> 
    <tr> 
     <td class="style3" valign="top"><?php echo($content); ?></td> 
    </tr> 
    <tr> 
     <td class="style4"><?php echo($endtitle); ?></td> 
    </tr> 
    <tr> 
     <td style="width: 600px; height: 30px"></td> 
    </tr> 
    <tr> 
     <td style="width: 600px; height: 100px" class="style5" valign="top"></td> 
    </tr> 
</table> 

STYLE1和2等等都是简单:

.style1 { 
    text-align: center; 
    font-family: Verdana, Geneva, Tahoma, sans-serif; 
    font-size: 32px; 
    color: #2B2B2B; 
    width: 600px; 
} 

,只有一些字体diferents

的firts图像显示了谷歌Chrome浏览器如何对其进行渲染,而第二火狐如何做到这一点: enter image description here

回答

0

您没有为您的td定义宽度,因此它需要父元素的整个宽度换货。如果您添加td {width:600px;}也将与Chrome相同。 如果您使用萤火虫检查td,您会发现DOM下的offsetWidth600,但如果您使用Chrome的开发人员工具进行相同操作,您会看到offsetWidth1900(或根据您的屏幕显示的任何值)。因此,要在所有浏览器中获得相同的结果,您必须按照上面所述设置固定宽度。

0

您应该将宽度设置在您的表格中。在你的td中设置宽度是不正确的形式。你的HTML应该是这样的:

<table cellpadding="0" cellspacing="0" style="width:600px"> 
    <tr> 
     <td rowspan="7"></td> 
     <td style="width: 600px; height: 100px;">&nbsp;</td> 
     <td rowspan="7"></td> 
    </tr> 
    <tr> 
     <td class="style1" valign="top"><?php echo($title); ?></td> 
    </tr> 
    <tr> 
     <td class="style2" valign="top"><?php echo($subtitle); ?></td> 
    </tr> 
    <tr> 
     <td class="style3" valign="top"><?php echo($content); ?></td> 
    </tr> 
    <tr> 
     <td class="style4"><?php echo($endtitle); ?></td> 
    </tr> 
    <tr> 
     <td style="width: 600px; height: 30px"></td> 
    </tr> 
    <tr> 
     <td style="width: 600px; height: 100px" class="style5" valign="top"></td> 
    </tr> 
</table> 

和你的造型看起来应该像:

.style1 { 
    text-align: center; 
    font-family: Verdana, Geneva, Tahoma, sans-serif; 
    font-size: 32px; 
    color: #2B2B2B; 
    width: 100%; 
}