博客列表 >Bootstrap全局样式中的表格与表单--2018-9-25

Bootstrap全局样式中的表格与表单--2018-9-25

晓明的博客
晓明的博客原创
2018年09月26日 11:55:23802浏览
  1. 表格布局的使用

    1)标签


  1. <table>    为表格添加基础样式。    

  2. <thead>    表格标题行的容器元素(<tr>),用来标识表格列。    

  3. <tbody>    表格主体中的表格行的容器元素(<tr>)。    

  4. <tr>    一组出现在单行上的表格单元格的容器元素(<td> 或 <th>)。    

  5. <td>    默认的表格单元格。    

  6. <th>    特殊的表格单元格,用来标识列或行(取决于范围和位置)。必须在 <thead> 内使用。    

  7. <caption>    关于表格存储内容的描述或总结。

    2)样式类

  8. .table    为任意 <table> 添加基本样式 (只有横向分隔线)    尝试一下    

  9. .table-striped    在 <tbody> 内添加斑马线形式的条纹 ( IE8 不支持)    尝试一下    

  10. .table-bordered    为所有表格的单元格添加边框    尝试一下    

  11. .table-hover    在 <tbody> 内的任一行启用鼠标悬停状态    尝试一下    

  12. .table-condensed    让表格更加紧凑    

    3)

  13. .active    将悬停的颜色应用在行或者单元格上    尝试一下    

  14. .success    表示成功的操作    尝试一下    

  15. .info    表示信息变化的操作    尝试一下    

  16. .warning    表示一个警告的操作    尝试一下    

  17. .danger    表示一个危险的操作    


  18. 实例

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <link rel="stylesheet" href="../lib/dist/css/bootstrap.css">
        <title>表格</title>
    </head>
    <body>
    <!--创建容器与行与列-->
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <!--表格:基类 修饰类1/主题1 修饰类2/主题2 ...-->
                <table class="table table-bordered table-hover text-center">
                    <caption class="h3 text-center">我的表格</caption>
                    <!--表头-->
                    <thead>
                    <tr class="info">
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr class="danger">
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr class="success">
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td class="warning">X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    <tr>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                        <td>X</td>
                    </tr>
                    </tbody>
                </table>
    
    
    
            </div>
        </div>
    </div>
    </body>
    </html>

    运行实例 »

    点击 "运行实例" 按钮查看在线实例

二,表单的使用

   1)垂直或基本表单

   

实例

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../lib/dist/css/bootstrap.css">
    <title>默认垂直表单</title>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-6 col-md-offset-3">

            <h3 class="text-center">新用户注册</h3>

            <form>
                <!--标签+控件: label+input/select/...-->
                <!--form-group:表单控件组-->
                <div class="form-group">
                    <label for="email">邮箱:</label>
                    <input type="email" class="form-control" id="email" name="email" placeholder="Email">
                </div>

                <div class="form-group">
                    <label for="password">密码:</label>
                    <input type="password" class="form-control" id="password" name="password" placeholder="Password">
                </div>

                <div class="form-group">
                    <label for="file">文件上传:</label>
                    <input type="file" id="file" name="file">
                    <p class="help-block">文件必须是jpg/png/gif图片格式</p>
                </div>

                <div class="form-group">
                    <label for="level">学历:</label>
                    <select name="level" id="level" class="form-control">
                        <option value="0">高中</option>
                        <option value="1">本科</option>
                        <option value="2">博士</option>
                    </select>
                </div>

                <div class="form-group">
                    <label for="comment">留言:</label>
                    <textarea name="comment" id="comment" class="form-control" rows="3"></textarea>
                </div>

                <!--复选框与按钮组非常特殊,不能使用控件组进行控制-->
                <label>选择课程:</label>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="course[]" value="front"> 前端
                    </label>
                </div>

                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="course[]" value="server" checked> 后端
                    </label>
                </div>

                <div class="checkbox disabled">
                    <label>
                        <input type="checkbox" name="course[]" value="full-stack" disabled> 全栈
                    </label>
                </div>

                <!--将上面的复选框改成水平排列-->
                <label>选择课程:</label>
                <div class="checkbox-inline">
                    <label>
                        <input type="checkbox" name="course[]" value="front"> 前端
                    </label>
                </div>

                <div class="checkbox-inline">
                    <label>
                        <input type="checkbox" name="course[]" value="server" checked> 后端
                    </label>
                </div>

                <div class="checkbox-inline disabled">
                    <label>
                        <input type="checkbox" name="course[]" value="full-stack" disabled> 全栈
                    </label>
                </div>

                <label>选择性别:</label>
                <div class="radio">
                    <label>
                        <input type="radio" name="gender"  checked>男
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="gender">女
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="gender"  disabled>待定
                    </label>
                </div>

                <label>选择性别:</label>
                <div class="radio-inline">
                    <label>
                        <input type="radio" name="gender"  checked>男
                    </label>
                </div>
                <div class="radio-inline">
                    <label>
                        <input type="radio" name="gender">女
                    </label>
                </div>
                <div class="radio-inline">
                    <label>
                        <input type="radio" name="gender"  disabled>待定
                    </label>
                </div>

                <!--如果想省略掉checkbox和radio中的文本标签内容,怎么办?-->
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="name" aria-label="用户名">
                    </label>
                </div>
                <div class="radio">
                <label>
                    <input type="radio" name="name" aria-label="是否同意?">
                </label>
                </div>
                <br>
                <button type="button" class="btn btn-primary">提交</button>


            </form>

        </div>
    </div>
</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


2.内联表单

   

实例

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../lib/dist/css/bootstrap.css">
    <title>内联表单</title>
</head>
<body>
<!--内联表单: 所有的表单元素全部在同一行显示,通常来说不需要标签说明,必须在sm或以上屏幕才有效(> 768px)-->
<form class="form-inline">
    <div class="form-group">
        <label for="email" class="sr-only">邮箱:</label>
        <input type="text" class="form-control" id="email" name="email" placeholder="Email">
    </div>

    <div class="form-group">
        <label for="password" class="sr-only">密码:</label>
        <input type="password" class="form-control" id="password" name="password" placeholder="Password">
    </div>

    <div class="checkbox">
        <label>
            <input type="checkbox"> 记住密码
        </label>
    </div>

    <button class="btn btn-primary">登录</button>
</form>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

3.水平表单

实例

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../lib/dist/css/bootstrap.css">
    <title>内联表单</title>
</head>
<body>
<!--内联表单: 所有的表单元素全部在同一行显示,通常来说不需要标签说明,必须在sm或以上屏幕才有效(> 768px)-->
<form class="form-inline">
    <div class="form-group">
        <label for="email" class="sr-only">邮箱:</label>
        <input type="text" class="form-control" id="email" name="email" placeholder="Email">
    </div>

    <div class="form-group">
        <label for="password" class="sr-only">密码:</label>
        <input type="password" class="form-control" id="password" name="password" placeholder="Password">
    </div>

    <div class="checkbox">
        <label>
            <input type="checkbox"> 记住密码
        </label>
    </div>

    <button class="btn btn-primary">登录</button>
</form>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

3.水平表单

  

实例

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../lib/dist/css/bootstrap.css">
    <title>水平表单</title>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <h3 class="text-center">用户登录</h3>
            <!--水平表单: -->
            <form action="" class="form-horizontal">
                <div class="form-group">
                <label for="email" class="col-sm-2 control-label">邮箱:</label>
                <div class="col-sm-10">
                    <input type="email" id="email" class="form-control" placeholder="Email">
                </div>

            </div>
                <div class="form-group has-error input-lg">
                    <label for="password" class="col-sm-2 control-label">密码:</label>
                    <div class="col-sm-10">
                        <input type="password" id="password" class="form-control" placeholder="Password">
                    </div>

                </div>

                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <div class="checkbox">
                            <label>
                                <input type="checkbox" name="" id="" checked> 记住密码
                            </label>
                        </div>
                    </div>
                </div>


                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary btn-block">登录</button>
                    </div>
                </div>



            </form>
        </div>
    </div>
</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议