gpt4 book ai didi

css - 使用css在同一行上的标签和文本框

转载 作者:技术小花猫 更新时间:2023-10-29 10:13:59 25 4
gpt4 key购买 nike

当创建一个新的 asp.net mvc3 应用程序时,您将获得登录和注册表单,其中文本字段上方有一个标签。我想更改它,使标签和字段都在同一行并对齐

下面的不行

@using (Html.BeginForm()) {
<div>
<fieldset>
<legend>Account Information</legend>

<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</div>

<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password)
</div>

<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>

<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>

CSS:

.display-label, 
.editor-label
{
display:inline-block;
width: 200px;
text-align: right;
margin-right: 10px;

}

.display-field,
.editor-field
{
display:inline-block;
margin: 0.5em 0 0 0;
}

最佳答案

我通常将标签向左浮动,输入在其旁边排成一行。这是一个例子:http://jsfiddle.net/qXFLa/

这是我如何重新安排您的代码的示例:

<div class="editor">
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</div>

然后,对于你的 CSS:

.editor label {
float: left;
width: 30px; // just putting an example here - but give them a width to align better
text-align: right; // this right-aligns them with the input
}

.editor input[type=text] {
width: 80px; // just putting an example value in here to make your inputs uniform in length
margin: 0 0 0 10px; // just some breathing room from the labels
}

关于css - 使用css在同一行上的标签和文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6437621/

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