场景:我想通过ASPX页面显示如下内容
State : <dropdown>
zip : <textbutton>
请注意,州和城市的“:”在所有行中都应该相同。目前我在下面得到一些东西。
State : <dropdown>
zip : <textbutton>
我一定是做错了什么,但我还不知道。感谢任何输入,
到目前为止,这是我的代码,
<div style="text-align:center" >
<asp:Label runat="server" id="StateCategory" Text ="State:" CssClass="LabelLeftAligned" />
<asp:DropDownList runat="server" ID="StateDDown" DataTextField="Name" AppendDataBoundItems="true"></asp:DropDownList>
</div>
<div style="text-align:center" >
<asp:Label runat="server" id="lblzipCode" Text ="Zip:" CssClass="LabelLeftAligned" />
<asp:TextBox ID="txtboxZipcode" runat="server" MaxLength="5" />
</div>
LabelLeftAligned 类在下面的样式表中定义。
.LabelLeftAligned {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: black;
font-weight: bold;
text-align: left;
}
最佳答案
将标签变成 block 级元素,给它一个宽度并右对齐。
类似于:(完整示例)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style>
.LabelRightAligned {
display:block;
width: 150px;
text-align:right;
float:left;
}
.ddl {
float:left;
margin-left:10px;
}
</style>
</head>
<body>
<div style="text-align:center;clear:both;">
<span class="LabelRightAligned">State:</span>
<select class="ddl">
<option value="volvo" />
<option value="chevy" />
</select>
</div>
<div style="text-align:center;clear:both;">
<span class="LabelRightAligned">zip:</span>
<input type="text" name="zip" id="zip" value="23423" class="ddl" />
</div>
</body>
</html>
例子如下:
关于asp.net - ASPX 页面上的格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7909284/