在页面中心制作一个面板表格

时间:2013-11-21 10:45:31

标签: asp.net css vb.net twitter-bootstrap-3

所以我试图创建一个带有Twitter Bootstrap的表单面板到页面的中心,希望即使在浏览器调整大小时,它仍然处于中心位置, here's我在jsfiddle上尝试过的,问题是我似乎无法使其成为中心,任何人都有想法?完整的代码在下面

<div class="container">
        <div class="row">
            <div class="panel panel-default">
                <div class="panel-body">
                    <legend>User Login</legend>
                    <form role="form">
                        <div class="form-group">
                            <label for="inputEmail">
                                Username</label>
                            <input id="inputEmail" type="text" class="form-control" placeholder="ex: John.Doe"
                                required="" />
                        </div>
                        <div class="form-group">
                            <label for="inputPassword">
                                Password</label>
                            <input id="inputPassword" type="password" class="form-control" placeholder="*******"
                                required="" />
                        </div>
                        <div class="checkbox">
                            <label>
                                <input id="chkRememberMe" type="checkbox" />
                                Remember Me
                            </label>
                        </div>
                        <button id="btnSubmit" type="submit" class="btn navbar-custom">
                            Submit</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

预览: enter image description here

3 个答案:

答案 0 :(得分:6)

请替换

<div class="panel panel-default">

用这个

<div class="panel panel-default" style="max-width:400px;margin-left:auto; margin-right:auto;">

答案 1 :(得分:2)

您还可以使用列来调整面板的大小和居中,例如:

<div class="container">
    <div class="row">
        <div class="col-md-offset-3 col-md-6">
            <div class="panel panel-default">
                <div class="panel-body">
                    <legend>User Login</legend>

                    <form role="form">
                        <div class="form-group">
                            <label for="inputEmail">Username</label>
                            <input id="inputEmail" type="text" class="form-control" placeholder="ex: John.Doe" required="" />
                        </div>

                        <div class="form-group">
                            <label for="inputPassword">Password</label>
                            <input id="inputPassword" type="password" class="form-control" placeholder="*******" required="" />
                        </div>

                        <div class="checkbox">
                            <label>
                                <input id="chkRememberMe" type="checkbox" />
                                Remember Me
                            </label>
                        </div>

                        <button id="btnSubmit" type="submit" class="btn navbar-custom">Submit</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

答案 2 :(得分:0)

尝试在div的样式属性中设置边距:

style="margin-left:auto;margin-right:auto;"

希望它有效......