您好,我得到了下面的部分 View ,它将在 div 中显示控件,但是控件创建的总是比 div 长,有没有更好的方法在 css 中进行控制而不是对每个控件的宽度进行硬编码?
<fieldset class="fieldsetthinner">
<div style="float: left; width: 10%"><p>@Html.EditorFor(model => model.decBeginQty)<p></div>
<div style="float: left; width: 10%"><p>@Html.EditorFor(model => model.decEndQty )<p></div>
<div style="float: left; width: 10%"><p>@Html.EditorFor(model => model.decBeginAmt )<p></div>
<div style="float: left; width: 10%"><p>@Html.EditorFor(model => model.decEndAmt )<p></div>
<div style="float: left; width: 20%"><p>@Html.EditorFor(model => model.tintFactorType)<p></div>
<div style="float: left; width: 10%"><p>@Html.EditorFor(model => model.decMaxBonus )<p></div>
<div style="float: left; width: 10%"><p>@Html.EditorFor(model => model.nvarMsg )<p></div>
<div style="float: left; width: 10%"><p>@Html.EditorFor(model => model.varVCode )<p></div>
</fieldset>
提前致谢
最佳答案
是这样的吗?
<fieldset class="fieldsetthinner">
<div class="editor"><p>THIS IS AN EDITOR<p></div>
<div class="editor"><p>THIS IS AN EDITOR<p></div>
<div class="editor"><p>THIS IS AN EDITOR<p></div>
<div class="editor"><p>THIS IS AN EDITOR<p></div>
<div class="editor2"><p>THIS IS AN EDITOR<p></div>
<div class="editor"><p>THIS IS AN EDITOR<p></div>
<div class="editor"><p>THIS IS AN EDITOR<p></div>
<div class="editor"><p>THIS IS AN EDITOR<p></div>
</fieldset>
CSS
fieldset.fieldsetthinner
{
background-color:gray;
}
.editor
{
float:left;
width:10%;
background-color:red;
}
.editor2
{
background-color:blue;
float:left;
width:20%;
}
只需将其添加到您的 CSS 中即可。我添加了背景颜色以向您展示差异。您可以使用 class 或 id,这样您就不会像您正在做的那样重复输入类似的样式。
这是工作 FIDDLE
关于css - 如何确保 MVC 在 div 中生成控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17807998/