青风百里

Bootstrap 表单
一.垂直表单在button标签中添加but-block类样式,可以使得按钮变成块级元素<div class=...
扫描右侧二维码阅读全文
12
2018/06

Bootstrap 表单

一.垂直表单


  • button标签中添加but-block类样式,可以使得按钮变成块级元素
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <form action="" role="form">
                <fieldset>
                    <legend>注册</legend>
                    <div class="form-group">
                        <label for="name">用户名:</label>
                        <input type="text" id="name" class="form-control" placeholder="邮箱/手机号">
                        <p class="help-block">可以使用手机号和邮箱注册</p>
                    </div>
                    <div class="form-group">
                        <label for="pwd">密码:</label>
                        <input type="password" id="pwd" class="form-control" placeholder="密码不少于6位">
                        <p class="help-block">密码不少于6位</p>
                    </div>
                </fieldset>
                <button type="submit" name="button" class="btn btn-info btn-block">确认</button>
            </form>
        </div>
    </div>
</div>

二.内联表单


  • form标签中添加form-inline类样式,可以使得表单变为内联表单
  • label标签中添加sr-only类样式,可以使得label标签隐藏
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <form action="" role="form" class="form-inline">
                <fieldset>
                    <legend>注册</legend>
                    <div class="form-group">
                        <label for="name">用户名:</label>
                        <input type="text" id="name" class="form-control" placeholder="邮箱/手机号">
                    </div>
                    <div class="form-group">
                        <label for="pwd">密码:</label>
                        <input type="password" id="pwd" class="form-control" placeholder="密码不少于6位">
                    </div>
                    <button type="submit" name="button" class="btn btn-info">确认</button>
                </fieldset>
            </form>
        </div>
    </div>
</div>

三.水平表单


  • 水平指的是label标签和input标签在同一行
  • 不再需要div.rowdiv.col-md-12来包裹表单,此时表单充当了.row.col-md-12
  • button向右偏移了2个栅格,自身占据10个栅格

<div class="container">
    <form action="" role="form" class="form-horizontal">
        <fieldset>
            <legend>注册</legend>
            <div class="form-group">
                <label for="name" class="col-md-2 control-label">用户名:</label>
                <div class="col-md-10">
                    <input type="text" id="name" class="form-control" placeholder="邮箱/手机号">
                </div>
            </div>
            <div class="form-group">
                <label for="pwd" class="col-md-2 control-label">密码:</label>
                <div class="col-md-10">
                    <input type="password" id="pwd" class="form-control" placeholder="密码不少于6位">
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <button type="submit" name="button" class="btn btn-info">确认</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>

Last modification:June 12th, 2018 at 03:56 pm

Leave a Comment