<div>成<tr>:是不是正确?

mar*_*zzz 14 html html-table tablerow

这段代码是否正确?

<table>
    <tr>
        <td>...</td>
    </tr>

    <tr>
        <div>...</div>
    </tr>

    <tr>
        <td>...</td>
    </tr>    
</table>    
Run Code Online (Sandbox Code Playgroud)

不知道语义(和W3C规则).你能说些什么?

Fel*_*ing 23

不,它无效.tr元素只能包含thtd元素.从HTML4规范:

<!ELEMENT TR       - O (TH|TD)+        -- table row -->
<!ATTLIST TR                           -- table row --
  %attrs;                              -- %coreattrs, %i18n, %events --
  %cellhalign;                         -- horizontal alignment in cells --
  %cellvalign;                         -- vertical alignment in cells --
>
Run Code Online (Sandbox Code Playgroud)

  • @markzzz:我不明白你的意思,你可以用 CSS 指定宽度,或者使用 `colspan` 属性,这取决于你想要什么。 (2认同)

Alo*_*hci 13

它不仅无效,而且不起作用!这个加价

<table>
    <tr>
        <td>The First Row</td>
    </tr>

    <tr>
        <div>The Second Row</div>
    </tr>

    <tr>
        <td>The Third Row</td>
    </tr>    
</table> 
Run Code Online (Sandbox Code Playgroud)

生成此显示

The Second Row
The First Row
The Third Row
Run Code Online (Sandbox Code Playgroud)

div完全从表中弹出并放在DOM中

http://jsfiddle.net/ELzs3/1/


sha*_*hat 5

不,你不应该div在表内使用,因为它是一个块级元素.您可以使用CSS覆盖行为,但如果这是您的目标,则不会使用W3C进行验证.