Bootstrap中心表格和表格下的一些文字

时间:2016-03-25 19:54:48

标签: html css twitter-bootstrap twitter-bootstrap-3

Not center

<div class="row">
    <div class="col-md-4">

    </div>
    <div class="col-md-4">       
        <div class="center-block text-center">
            <form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal" role="form">
                <div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
                <div class="form-group">
                    <div class="col-md-10">
                        <input asp-for="Email" placeholder="Email" class="form-control" />
                        <span asp-validation-for="Email" class="text-danger"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-10">
                        <input asp-for="Password" placeholder="Password" class="form-control" />
                        <span asp-validation-for="Password" class="text-danger"></span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-10">
                        <button type="submit" class="btn btn-block">Sign in</button>
                    </div>
                </div>
            </form>         
            <p>
                <a asp-controller="Home" asp-action="Register">Sign up</a>
            </p>
            <p>
                <a asp-action="ForgotPassword">Forgot your password?</a>
            </p>
            <p>
                <a asp-controller="Home" asp-action="Index">Return</a>
            </p>          
        </div>
    </div>
    <div class="col-md-4">

    </div>
</div>

2 个答案:

答案 0 :(得分:1)

文本居中,但表单的宽度为10/12(83%)。您应该将col-md-10更改为col-md-12

<div class="form-group">
    <div class="col-md-12">
        <input asp-for="Email" placeholder="Email" class="form-control" />
        <span asp-validation-for="Email" class="text-danger"></span>
    </div>
</div>
<div class="form-group">
    <div class="col-md-12">
        <input asp-for="Password" placeholder="Password" class="form-control" />
        <span asp-validation-for="Password" class="text-danger"></span>
    </div>
</div>
<div class="form-group">
    <div class="col-md-12">
        <button type="submit" class="btn btn-block">Sign in</button>
    </div>
</div>

答案 1 :(得分:0)

我认为最好删除col-md-10类:

<div class="form-group">
    <div class="">
        <input asp-for="Email" placeholder="Email" class="form-control" />
        <span asp-validation-for="Email" class="text-danger"></span>
    </div>
</div>
<div class="form-group">
    <div class="">
        <input asp-for="Password" placeholder="Password" class="form-control" />
        <span asp-validation-for="Password" class="text-danger"></span>
    </div>
</div>
<div class="form-group">
    <div class="">
        <button type="submit" class="btn btn-block">Sign in</button>
    </div>
</div>