我在mvc 4上有一个标准的登录页面,它运行正常,但我的html知识非常薄弱,我需要一个快速的答案,在我安装twitter bootstrap之后整理表单,用户名和密码标签都粘在同一个在表单中的行,有人可以建议快速修复我的代码,谢谢
@model MvcApplication2.Models.login_details
@{
ViewBag.Title = "Log in";
}
<br /><br /><br />
<h2>@ViewBag.Title.</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="col-md-10">
@Html.LabelFor(m => m.username, new { @class = "col-md-2 control-label"})
<div class="col-md-10">
@Html.TextBoxFor(m => m.username, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.username, "", new { @class = "text-danger"})
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.password, new { @class = "col-md-2 control-label"})
<div class="col-md-10">
@Html.PasswordFor(m => m.password, new { @class = "form-control"})
@Html.ValidationMessageFor(m => m.password, "", new { @class = "text-danger"})
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default" />
</div>
</div>
}
</section>
</div>
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
答案 0 :(得分:0)
容易:) 只需将LabelFor的类从col-md-2更改为col-md-3,然后添加另一个项目text-left。
所以你的标签应该是这样的:
@Html.LabelFor(m => m.Email, new { @class = "col-md-3 control-label text-left" })
@Html.LabelFor(m => m.Password, new { @class = "col-md-3 control-label text-left" })
然后转到Site.css(〜/ Content / site.css)并在底部添加以下内容:
.form-horizontal .control-label.text-left{
text-align: left;
}
我会建议您学习HTML / JS / Bootstrap,就好像您的专业制作网站一样,您几乎总是必须能够胜任基本的HTML / JS / Bootstrap(有时)