由于某种原因,我的div标签被包裹在此页面上的form标签中。我所能想到的只是asp:literal是元凶,但我不知道为什么会这样?在文件后面的代码中,我正在插入一个表,但是为什么它会使我的页脚div包裹在其中呢?下面有一张img,显示了Google Chrome浏览器的开发人员显示的内容,而我对为什么将页脚div搞不清楚感到困惑。
我使用了普通的页脚和主要标签,但结果仍然相同。我尝试重新做我的div层次结构无济于事。现在,我在CSS中的页脚具有绝对位置,该位置与容器div关联,以试图使其固定在底部,这确实有助于将其保持在底部,但是如您在图像中所见,它是由于我在包含表单的div上的样式,因此请不要一直停留在应该放置的位置,并且在渲染时它会向右移动。啊!
现在,我在网站上还有另外三个页面,其中包含表单,这不是问题,这就是为什么我可以肯定的是,在文件背后的代码中创建了表格,这是可以解决的。
这是.aspx文件的一部分
<div id="body">
<div class="intro">
<div class="center">
<h2>Current Schedule</h2>
<form id="scheduleForm" runat="server">
<asp:Literal ID="schedule" runat="server" />
</form>
</div>
</div>
</div>
<div id="footer">
<p>2010 © Copyright Central Valley Utilities. All rights reserved. Read Legal policy and Privacy policy.</p>
</div>
</div>
</body>
</html>
这是文件后面的代码,该文件为asp:Literal标签“ schedule”创建表。
if (scheduleRecords.Read())
{
schedule.Text += "<table width='100%' border='1'>";
schedule.Text += "<tr><th>Class</th><th>Days</th><th>Time</th>";
do
{
schedule.Text += "<tr>";
schedule.Text += "<td>" + scheduleRecords["class"] + "</td>";
schedule.Text += "<td>" + scheduleRecords["days"] + "</td>";
schedule.Text += "<td>" + scheduleRecords["time"] + "</td>";
schedule.Text += "</tr>";
} while (scheduleRecords.Read());
schedule.Text += "</tr>";
Google Chrome输出的JPG,显示表单上方的页脚
最佳答案
您的</div>
标记太多,因此<div id='body'>
标记在页脚之前关闭。
<div id="body">
<div class="intro">
<div class="center">
<h2>Current Schedule</h2>
<form id="scheduleForm" runat="server">
<asp:Literal ID="schedule" runat="server" />
</form>
</div>
</div>
</div> <-- Here
<div id="footer">
<p>2010 © Copyright Central Valley Utilities. All rights reserved. Read Legal policy and Privacy policy.</p>
</div>
</div> <-- Or Here
删除这两个div之一(可能是第二个)。
另外,您的文字代码不会创建结束表标记。
if (scheduleRecords.Read())
{
schedule.Text += "<table width='100%' border='1'>";
schedule.Text += "<tr><th>Class</th><th>Days</th><th>Time</th></tr>"; <-- move </tr> to here
do
{
schedule.Text += "<tr>";
schedule.Text += "<td>" + scheduleRecords["class"] + "</td>";
schedule.Text += "<td>" + scheduleRecords["days"] + "</td>";
schedule.Text += "<td>" + scheduleRecords["time"] + "</td>";
schedule.Text += "</tr>";
} while (scheduleRecords.Read());
schedule.Text += "</table>"; <-- Here
}
关于html - 我的div神秘地包裹在我的表单中。我该如何解决?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37199741/