css - 如何确保 MVC 在 div 中生成控件?

标签 css asp.net-mvc

您好,我得到了下面的部分 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/

相关文章:

javascript - jQuery AJAX + 帮助隐藏此内容

html - Bootstrap Accordion 优缺点问题

c# - 从 MVC Controller 返回一个字符串到 jQuery

javascript - Bootstrap 星级评定 onclick 不开火

html - 如何在 svg 符号中表示 x 和 y

html - 将 div 内的图像右对齐

.net - 创建需要类型信息的 MVC3 ValueProviderFactories?

jquery - Kendo mvc刷新tabstrip中的选项卡之一

asp.net-mvc - MVC 项目没有为此对象定义无参数构造函数

html - 用于 Internet Explorer 检测的条件 HTML 语句