1

我正在尝试使用有效的文档类型,但是如果我使用下面的带有 URL 的文档类型,则链接拒绝保持#ffffff在 200 宽度表中分配的文本颜色(并且)背景颜色会擦除两行(两者谷歌和雅虎链接)。注释掉 Doctype URL,它工作正常......任何人都可以对此有所了解>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01     Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test.com</title>
<style type="text/css">
td.off{background: #223C66}
td.on{background: #2d2dff}
</style>
<style>
a{text-decoration:none}
a:hover{text-decoration:underline}
</style>
</head>

<table width="600" align="center" style="border:10px solid black; border-collapse:collapse;" cellpadding="10" cellspacing="0">

<tr>
<td>

<table width="200" cellpadding="0" cellspacing="10" border="0">
<tr>
<td height="40" class="off" onmouseover="this.className='on'" onmouseout="this.className='off'">
<a href="http:\\www.google.com"><font color=#ffffff size=2 face=arial>valid google link</font></a>
</td>
</tr>

<tr>
<td height="40" class="off" onmouseover="this.className='on'" onmouseout="this.className='off'">
<a href="http://www.yahoo.com" target="_blank"><font color=#ffffff size=2 face=arial>valid yahoo link</font></a>
</td>
</tr>

</table>

</td>

<td style="border:1px solid black; border-collapse:collapse;" cellpadding="0" cellspacing="0">
<a href="http:\\www.msn.com">valid msn.com link</a>
<p>plain test - no link</p>
</td>
</tr>

</table>
</body>
</html>
4

1 回答 1

4

您需要确保所有属性值都用"引号括起来才能有效。

例如:

<font color="#ffffff" size="2" face="arial">

此外,在标记上使用验证工具是一种很好的做法:W3C 标记验证服务 http://validator.w3.org/check

补充:带有适当标记的完整版本,应验证为 HTML 4.01 过渡

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>test.com</title>
        <style type="text/css">
            td.off {
                background: #223C66;
            }
            td.on {
                background: #2d2dff;
            }
            a {
                text-decoration:none;
            }
            a:hover {
                text-decoration:underline;
            }
        </style>
    </head>
    <body>
        <table width="600" align="center" style="border:10px solid black; border-collapse:collapse;">
            <tr>
                <td>
                    <table width="200" border="0">
                        <tr>
                             <td height="40" class="off" onmouseover="this.className='on'" onmouseout="this.className='off'">
                                 <a href="http://www.google.com"><font color="#ffffff" size="2" face="arial">valid google link</font></a>
                             </td>
                        </tr>
                        <tr>
                             <td height="40" class="off" onmouseover="this.className='on'" onmouseout="this.className='off'">
                                 <a href="http://www.yahoo.com" target="_blank"><font color="#ffffff" size="2" face="arial">valid yahoo link</font></a>
                             </td>
                        </tr>
                    </table>
              </td>
              <td style="border:1px solid black; border-collapse:collapse;" >
                  <a href="http://www.msn.com">valid msn.com link</a>
                  <p>plain test - no link</p>
               </td>
            </tr>
        </table>
    </body>
</html>
于 2013-03-13T23:48:59.143 回答