php - 无法将 <table> 标签放入 div 标签内

标签 php html css xhtml

我正在尝试将 a 放入标签内,如下例所示,但表格显示在 tableWrapper div 之外,tableWrapper div 正确显示我想要但表格在它外面,我不明白是什么我做错了,有人可以帮忙吗? :

//the buttons 
$html .= '<p><form method="post" action = "DBTest.php" >
    <input type="submit" name="create" value="Create">
    <input type="submit" name="save" value="Save">
    <input type="submit" name="reset" value="Reset">
    </form></p>';   


//start table
$html.= '<div id = "tableWrapper"><table>';

foreach($rows as $row)
    {

         $id= $row['id'];
         $title = $row['title'];
         $year = $row['YEAR'];
        //put everything on a table
        $html.= "<tr><td>" . $row['id'] . "</td><td>" . $row['title'] . "</td><td>"  . $row['year'] . "</td><td>";
     }
$html.= '</table></div>';    

//the main body
$alpha['main'] = <<<EOD

{$html}

EOD;

这是我的 tablWrapper div:

#tableWrapper{
    clear:both;
    width: 350px;
    height: 350px;
}

这是我的表格 CSS:

table {margin-bottom:1.4em;}
th {font-weight:bold;background:black;color:white;}
th,td,caption {padding:4px 10px 4px 5px;}


tbody tr:nth-child(even) td {background:#A1912A11;}
tbody tr:hover td {background:#9E9E80;}

提前致谢

最佳答案

错别字:

    $html.= "<tr><td>" [...snip...] . "</td><td>";
                                            ^^^^

你永远不会关闭你的 <tr>标签,并以新的未终止 <td> 结束该行.所以你最终得到了

<div><table>
<tr><td>...</td><td>..</td><td>
<tr><td>...</td><td>..</td><td>
etc...

关于php - 无法将 <table> 标签放入 div 标签内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19931946/

相关文章:

html - 在 ASP.NET 的新选项卡中打开超链接

javascript - 带图像的心跳效果转场

打开其他链接后jquery click事件不起作用

html - 是否可以选择所有没有任何 CSS 类的元素?

php - 在 Slim DI 服务中传递参数

php mysql 如果查询为空则退出

php - 如何使用 PHP readdir 排除某些文件类型?

html - 在网页中嵌入 Powerpoint

css - 试图弄清楚为什么一个图像在容器外缩放

php - 将 MYSQL 查询从 for 循环中取出