表格是bootstrap 的一个基础组件之一,bootstrap 为表格提供了一种基础样式 和四种附件样式,使用bootstrap 表格时候,只需添加对应类名即可获得不同风格。

  • table :基础表格
  • .table-striped 斑马线表格
  • .table-bordered 带边框表格
  • .table-hover 隔行变色
  • .table-condensed 紧凑型表格
  • .table-responsive 响应式(宽度不够自动添加滚动条)

基础表格

  1. <table class="table"></table>

支持表格元素

<table>         添加基础样式
<thead>            表格标题行容器元素
<tbody>
<tr>
<td>
<th>                
<caption>        表格标题
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bootstrap 网页</title>
    <link rel="stylesheet" href="./css/bootstrap.min.css" rel="stylesheet">
    <script src="./js/jquery-3.3.1.min.js"></script>
    <script src="./js/bootstrap.bundle.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <style rel="stylesheet">
        .content {
            width: 620px;
            height: 220px;
            margin:10px 20px;
        }
    </style>
</head>
<body>

    <div class="container">

        <h2> 基本样式</h2>
        <table style="width: 500px;" class="table">
            <thead>
                <tr>
                    <th>科目</th>
                    <th>成绩</th>

                <th>
            </thead>

            <tbody>
                <tr>
                    <td>高数</td>
                    <td>80</td>
                </tr>
                <tr>
                    <td>英语</td>
                    <td>90</td>
                </tr>
                <tr>
                    <td>计算机</td>
                    <td>96</td>
                </tr>
            </tbody>
        </table>
    </div>


</body>
</html>

image.png
条纹状

<table class="table table table-striped">

image.png
带边框

状态类

状态类可以为行为或单元格设置颜色,提供诸如光标所在行颜色,标志,警告信息。

  • .actitive 悬停时设置颜色
  • .success 标志成功或积极的动作
  • .info 标志普通的提示
  • .warning 标志警告或用户需要注意的
  • .danger 标志警告或潜在的负面隐形 ```html

    基本样式

    科目 成绩
    高数 80
    英语 90
    计算机 96

```