Asp.Net MVC 5 + Bootstrap. How make inputs fit screen width?

人走茶凉 提交于 2020-01-16 04:33:45

问题


I really don't know what I'm doing wrong. I want my textboxes with same size of my buttons below. I already tried change a lot in the cshtml but without success.

Below my cshtml file:

@model SomeModel.Models.LoginViewModel

<div class="row">
    <div class="col-md-8 col-sm-12 col-xs-12">
        <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)
                <div class="form-group">
                    @Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
                    <div class="col-md-12">
                        @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.UserName)
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
                    <div class="col-md-12">
                        @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Password)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-12 col-xs-12">
                        <button type="submit" class="btn btn-success btn-block">Entrar</button>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-10 col-sm-12 col-xs-12 visible-sm visible-xs">
                        <button type="submit" class="btn btn-primary btn-block">Ainda Não Tenho Conta</button>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-10 col-sm-12 col-xs-12 visible-sm visible-xs">
                        <button type="submit" class="btn btn-info btn-block">Esqueci Meu Usuário Ou Senha</button>
                    </div>
                </div>
                <p>
                    @Html.ActionLink("Register", "Register") if you don't have a local account.
                </p>
            }
        </section>
    </div>
</div>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

What am I doing wrong?


回答1:


The default MVC5 template has a css rule in Site.css:

input, select, textarea { max-width: 280px; }

I usually remove this rule.

It causes problems with Bootstrap v3 input group where the input box does not extend to its container's width.



来源:https://stackoverflow.com/questions/30958361/asp-net-mvc-5-bootstrap-how-make-inputs-fit-screen-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!