【发布时间】:2019-07-16 01:38:14
【问题描述】:
我正在使用引导表单控件,并且尝试将 TextBoxFor 元素宽度设置为 100%。但如下图所示。
我的代码如下。
@model LearnWord.Models.WordModels
@{
ViewBag.Title = "Add";
}
<h2>Add New Word</h2>
@using (Html.BeginForm("Add", "Word"))
{
<div class="form-group">
@Html.LabelFor(m => m.Word)
@Html.TextBoxFor(m => m.Word, new { @class = "form-control" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Meaning)
@Html.TextBoxFor(m => m.Meaning, new { @class = "form-control" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Synonyms)
@Html.TextAreaFor(m => m.Synonyms, new { @class = "form-control" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Sentences)
@Html.TextAreaFor(m => m.Sentences, new { @class = "form-control" })
</div>
<button type="submit" class="btn btn-primary">Save</button>
}
这是渲染 body 的 _Layout.cshtml 部分。
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - Created By ChivalrouS</p>
</footer>
</div>
我尝试将宽度设置为 100%,但它已经是这样了。当我尝试用 100px 或 200px 更改宽度时,它可以工作,但 TextBox 并没有将页面覆盖为 100%。
我检查了其他主题,但找不到我的问题的解决方案。
【问题讨论】:
-
取决于外部容器。它占外容器宽度的 100%。所以如果你喜欢
col-lg-6,它将覆盖col-lg-6的宽度等等 -
没有这样的约束,实际上包含该控件的是覆盖页面。当我向或外部部分添加边框时,它显示的比控件大。但控制不是。你能把这个页面的整个 html 粘贴过来吗?'body-content' 的 css 是什么它只是设置了'padding-right'和'padding-left'。
标签: css asp.net-mvc bootstrap-4 html.textboxfor