青风百里

Bootstrap 表格
一.默认表格<div class="container"> <div...
扫描右侧二维码阅读全文
12
2018/06

Bootstrap 表格

一.默认表格


<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table>
                <caption class="text-center h4">普通表格</caption>
                <thead>
                    <tr>
                        <th>学号</th><th>姓名</th><th>性别</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>001</td><td>李白</td><td>男</td>
                    </tr>
                    <tr>
                        <td>002</td><td>杨戬</td><td>男</td>
                    </tr>
                    <tr>
                        <td>003</td><td>王昭君</td><td>女</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

二.基本表格


  • table标签中添加table类样式
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table class="table">
                <caption class="text-center h4">普通表格</caption>
                <thead>
                    <tr>
                        <th>学号</th><th>姓名</th><th>性别</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>001</td><td>李白</td><td>男</td>
                    </tr>
                    <tr>
                        <td>002</td><td>杨戬</td><td>男</td>
                    </tr>
                    <tr>
                        <td>003</td><td>王昭君</td><td>女</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

三.隔行变色


  • table标签中追加table-striped类样式
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped">
                <caption class="text-center h4">普通表格</caption>
                <thead>
                    <tr>
                        <th>学号</th><th>姓名</th><th>性别</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>001</td><td>李白</td><td>男</td>
                    </tr>
                    <tr>
                        <td>002</td><td>杨戬</td><td>男</td>
                    </tr>
                    <tr>
                        <td>003</td><td>王昭君</td><td>女</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

四.带边框的表格


  • table中追加table-bordered类样式
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-bordered">
                <caption class="text-center h4">普通表格</caption>
                <thead>
                    <tr>
                        <th>学号</th><th>姓名</th><th>性别</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>001</td><td>李白</td><td>男</td>
                    </tr>
                    <tr>
                        <td>002</td><td>杨戬</td><td>男</td>
                    </tr>
                    <tr>
                        <td>003</td><td>王昭君</td><td>女</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

五.鼠标悬停变色


  • table标签中追加table-hover类样式
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover">
                <caption class="text-center h4">普通表格</caption>
                <thead>
                    <tr>
                        <th>学号</th><th>姓名</th><th>性别</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>001</td><td>李白</td><td>男</td>
                    </tr>
                    <tr>
                        <td>002</td><td>杨戬</td><td>男</td>
                    </tr>
                    <tr>
                        <td>003</td><td>王昭君</td><td>女</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

六.紧缩性表格


  • table标签中添加table-condensed类样式,使得表格的行高变小
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover table-condensed">
                <caption class="text-center h4">普通表格</caption>
                <thead>
                    <tr>
                        <th>学号</th><th>姓名</th><th>性别</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>001</td><td>李白</td><td>男</td>
                    </tr>
                    <tr>
                        <td>002</td><td>杨戬</td><td>男</td>
                    </tr>
                    <tr>
                        <td>003</td><td>王昭君</td><td>女</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

![图片上传中(0)...]

七.状态类


  • 在表格的tr标签中添加active succsee warning danger info,改变表格行的背景色
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover table-condensed">
                <caption class="text-center h4">普通表格</caption>
                <thead>
                    <tr>
                        <th>学号</th><th>姓名</th><th>性别</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="info">
                        <td>001</td><td>李白</td><td>男</td>
                    </tr>
                    <tr class="danger">
                        <td>002</td><td>杨戬</td><td>男</td>
                    </tr>
                    <tr class="success">
                        <td>003</td><td>王昭君</td><td>女</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

八.响应式表格


  • 将整个表格包裹在.table-responsive元素内
<div class="table-responsive">
    <table class="table table-striped table-bordered table-hover table-condensed">
        <caption class="text-center h4">普通表格</caption>
        <thead>
        <tr>
            <th>学号</th><th>姓名</th><th>性别</th>
        </tr>
        </thead>
        <tbody>
        <tr class="info">
            <td>001</td><td>李白</td><td>男</td>
        </tr>
        <tr class="danger">
            <td>002</td><td>杨戬</td><td>男</td>
        </tr>
        <tr class="success">
            <td>003</td><td>王昭君</td><td>女</td>
        </tr>
        </tbody>
    </table>
</div>

Last modification:June 12th, 2018 at 02:00 am

Leave a Comment