我正在尝试使用浮动 div 构建表单,而不是使用表格的正常方法。我已经到达提交按钮并试图将其居中。通常,作为块元素的 DIV 会自动用完一整行并在它之后有一个换行符,不是吗?但我的没有,我不知道为什么。我尝试将它的宽度明确设置为 100%,但它仍然不会使用全宽。更让我困惑的是,div 的样式是 clear:both; 我认为应该防止任何内容漂浮在它旁边。我还尝试将其以下文本放在自己的 div 中,但没有任何改变。为什么文本浮动在提交 div 旁边?
<style type="text/css">
#rlpContactForm
{
width:275px;
}
#rlpContactForm label
{
display:block;
float:left;
width:112px;
text-align:right;
font-weight:bold;
}
#rlpContactForm input
{
float:left;
margin:0 0 5px 5px;
}
#rlpContactForm input[type="text"]
{
border: 1px solid #999999;
}
#rlpContactForm input[type="text"]
{
width: 146px; /*175 available - total width of label (including margins/borders/10pxwiggle room)*/
padding: 1px 0px 1px 0px; /* Otherwise IE adds 1px right and left padding automatically */
}
#rlpContactForm input[type="text"].age
{
width: 44px; /* Sized for 3 boxes to fit 1 line */
margin: 0 0 5px 5px;
text-align:center;
}
#rlpContactForm .submit
{
float:none;
clear:both;
width:100%;
text-align:center;
}
</style>
...
<div id="rlpContactForm">
<label>First Name:</label>
<asp:TextBox ID="txtFName" runat="server" />
<label>Last Name:</label>
<asp:TextBox ID="txtLName" runat="server" />
<label>E-mail:</label>
<asp:TextBox ID="txtEmail" runat="server" />
<label>Phone:</label>
<asp:TextBox ID="txtPhone" runat="server" />
<label>Children's Ages:</label>
<asp:TextBox ID="txtAge1" runat="server" CssClass="age"/>
<asp:TextBox ID="txtAge2" runat="server" CssClass="age"/>
<asp:TextBox ID="txtAge3" runat="server" CssClass="age"/>
<div class="submit"><asp:Button ID="btnSubmit" runat="server" Text="Submit"/></div>
Thank you for your interest. A team member will contact you shortly.
</div>
IE 和 Firefox 显示喜欢
|Submit|Thank you for your interest. A
team member will contact you
shortly.