gpt4 book ai didi

asp.net - 使用 CSS 对齐表中的 ASP 控件

转载 作者:太空宇宙 更新时间:2023-11-04 04:57:50 28 4
gpt4 key购买 nike

我想对齐 ASP 标签和文本框,但我迷失在 CSS 森林中。控件对齐不好。 (抱歉,我的 CSS 代码不好。)我想将控件成对放置在彼此下方 (Label+TextBox)。请帮忙。

aspx 页面:

<asp:TableCell ID="tc0" runat="server" CssClass="searchTableLabelsCell">
<asp:Label ID="lblrefNo" runat="server" Text="RefNo:" CssClass="searchLabel">
</asp:Label>
<asp:TextBox ID="txtRefNo" runat="server" CssClass="textBoxes" MaxLength="50">
</asp:TextBox>
<asp:Label ID="lblFrom" runat="server" Text="From:" CssClass="searchLabel">
</asp:Label>
<asp:TextBox ID="txtFrom" runat="server" CssClass="textBoxes" MaxLength="50">
</asp:TextBox>
<asp:Label ID="lblTo" runat="server" Text="To:" CssClass="searchLabel">
</asp:Label>
<asp:TextBox ID="txtTo" runat="server" CssClass="textBoxes" MaxLength="50">
</asp:TextBox>
<asp:Label ID="lblCc" runat="server" Text="Cc:" CssClass="searchLabel">
</asp:Label>
<asp:TextBox ID="txtCc" runat="server" CssClass="textBoxes" MaxLength="50">
</asp:TextBox>
</asp:TableCell>

CSS

.searchTableLabelsCell
{
font: 12px Verdana;
width: 300px; /* it must be 300px */
border-style: none;
padding: 0px;
margin: 0px;
background-color: Aqua;
}
.searchLabel
{
float: left;
margin-right: 0px;
font: 13px Verdana;
text-align: right;
width: 50px;
background-color: Blue;
margin-top:15px;
position: relative;
left: 0px;
}
.textBoxes
{
width: 120px;
margin-top: 12px;
position: relative;
left: 0px;
resize: none;
}

请求对齐:

    lblrefNo    txtRefNo               <!--CELL WIDTH -->
lblFrom txtFrom <!--CELL WIDTH -->
lblTo txtTo <!--CELL WIDTH -->
lblCc txtCc <!--CELL WIDTH -->

IE(坏):

    lblrefNo            txtRefNo lblFrom    txtFrom <!--CELL WIDTH -->
lblTo txtTo lblCc txtCc <!--CELL WIDTH -->

Chrome(坏):

    lblrefNo        txtRefNo lblFrom
txtFrom lblTo
txtTo
lblCc txtCc

最佳答案

请尝试下面的 HTML

风格

.searchLabel
{
display: block;
}
.textBoxes
{
display: block;
}

HTML

<asp:TableCell ID="tc0" runat="server" CssClass="searchTableLabelsCell">
<div style="display:block; float: left; text-align: right;">
<asp:Label ID="lblrefNo" runat="server" Text="RefNo:" CssClass="searchLabel">
</asp:Label>
<asp:Label ID="lblFrom" runat="server" Text="From:" CssClass="searchLabel">
</asp:Label>
<asp:Label ID="lblTo" runat="server" Text="To:" CssClass="searchLabel">
</asp:Label>
<asp:Label ID="lblCc" runat="server" Text="Cc:" CssClass="searchLabel">
</asp:Label>
</div>
<div style="display:block; float: left; margin-left: 10px; text-align: left;">
<asp:TextBox ID="txtRefNo" runat="server" CssClass="textBoxes" MaxLength="50">
</asp:TextBox>
<asp:TextBox ID="txtFrom" runat="server" CssClass="textBoxes" MaxLength="50">
</asp:TextBox>
<asp:TextBox ID="txtTo" runat="server" CssClass="textBoxes" MaxLength="50">
</asp:TextBox>
<asp:TextBox ID="txtCc" runat="server" CssClass="textBoxes" MaxLength="50">
</asp:TextBox>
</div>
</asp:TableCell>

关于asp.net - 使用 CSS 对齐表中的 ASP 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12088618/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com