Css 标签和文本框位于同一行+;整个宽度上的文本框
默认情况下,在ASP.NET MVC中,当系统生成视图(脚手架)时,标签在一行,文本框在下一行。我想有标签和文本框在同一行,有整个宽度(100%)的文本框。我试图做到这一点,但没有成功 我发现了一些类似的帖子,但不允许我在整个宽度上使用文本框 以下是我想要的: 因此,默认情况下,我有:Css 标签和文本框位于同一行+;整个宽度上的文本框,css,asp.net-mvc,Css,Asp.net Mvc,默认情况下,在ASP.NET MVC中,当系统生成视图(脚手架)时,标签在一行,文本框在下一行。我想有标签和文本框在同一行,有整个宽度(100%)的文本框。我试图做到这一点,但没有成功 我发现了一些类似的帖子,但不允许我在整个宽度上使用文本框 以下是我想要的: 因此,默认情况下,我有: <div class="editor-label"> @Html.LabelFor(model => model.Descr) </div> <div class="edit
<div class="editor-label"> @Html.LabelFor(model => model.Descr) </div>
<div class="editor-field"> @Html.EditorFor(model => model.Descr) </div>
<div class="editor-label"> @Html.LabelFor(model => model.Year) </div>
<div class="editor-field"> @Html.EditorFor(model => model.Year) </div>
@Html.LabelFor(model=>model.Descr)
@EditorFor(model=>model.Descr)
@LabelFor(model=>model.Year)
@EditorFor(model=>model.Year)
有什么想法吗?这是一个纯粹的HTML/CSS问题,与ASP.NET MVC无关。我建议您使用CSS创建漂亮的HTML表单 因此,在您的例子中,您可以
float:left
标签并将其定义为固定宽度。正如我为你写的文章中所示:
.editor-label {
float: left;
width: 200px;
}
.editor-field {
margin-left: 200px;
}
.editor-field input {
width: 100%;
}
This is the correct answer:both label and textboxes are in the same line
.editor-label{
float: left;
width: 100%;
margin-bottom:-20px;
}
.editor-field
{
margin-left: 120px;
margin-bottom:-5px;
}
.display-label {
float: left;
padding: 0;
width: 160px;
}