先整体看一下效果,图中“已订购信息”下面的部分(红框圈出来的)就是用bootstrap-table做出来的
今天第一次接触这个插件,小小总结一下:
1 引入CSS、JS
先引入CSS、JS,优先引用第三方的文件,注意文件之间的依赖关系,如bootstrap依赖于jQuery,就应该先引用jquery.js,再引用bootstrap.js
注意:Bootstrap Table需要使用HTML5 doctype,如下:
<!doctype html>
<html lang="en">
...
</html>
在head中加载css样式:(先加载bootstrap.min.css,再加载bootstrap-table.min.css,最后再加载自己的样式)
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<!-- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"-->
<!-- integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">-->
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css">
<link rel="stylesheet" href="css/MyCss.css">
在结束</body>
标记之前加入JS文件:(先jQuery,然后Bootstrap.js、bootstrap-table.js,最后是自己的js文件)
对于Bootstrap v4,使用Font Awesome作为默认图标,因此需要导入Font Awesome链接。
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"
integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"
integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"
crossorigin="anonymous"></script>
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
<script src="js/main.js"></script>
2 引用好后直接使用即可
如下:
<table data-toggle="table" ><!--data-url="data1.json"-->
<thead>
<tr>
<th>组网名称</th>
<th>产品类型</th>
<th>更改时间</th>
<th>生效时间</th>
<th>到期时间</th>
<th>业务状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>联通-张三_0109</td>
<td>SD-WAN 智选专线平台</td>
<td>2019-07-03</td>
<td>-</td>
<td>2022-07-24</td>
<td>
<span class="dealing">处理中</span>
</td>
<td>处理中</td>
</tr>
<tr>
<td>联通-张三_0109</td>
<td>SD-WAN 智选专线平台</td>
<td>2019-07-03</td>
<td>-</td>
<td>2022-07-24</td>
<td>
<span class="normal_use">正常使用</span>
</td>
<td>
<span class="check">查看</span>
<span class="stop">终止</span>
<span class="change">变更</span>
</td>
</tr>
<tr>
<td>联通-张三_0109</td>
<td>SD-WAN 智选专线平台</td>
<td>2019-07-03</td>
<td>-</td>
<td>2022-07-24</td>
<td>
<span class="dealing">处理中</span>
</td>
<td>处理中</td>
</tr>
<tr>
<td>联通-张三_0109</td>
<td>SD-WAN 智选专线平台</td>
<td>2019-07-03</td>
<td>-</td>
<td>2022-07-24</td>
<td>
<span class="normal_use">正常使用</span>
</td>
<td>
<span class="check">查看</span>
<span class="stop">终止</span>
<span class="change">变更</span>
</td>
</tr>
<tr>
<td>联通-张三_0109</td>
<td>SD-WAN 智选专线平台</td>
<td>2019-07-03</td>
<td>-</td>
<td>2022-07-24</td>
<td>
<span class="dealing">处理中</span>
</td>
<td>处理中</td>
</tr>
<tr>
<td>联通-张三_0109</td>
<td>SD-WAN 智选专线平台</td>
<td>2019-07-03</td>
<td>-</td>
<td>2022-07-24</td>
<td>
<span class="normal_use">正常使用</span>
</td>
<td>
<span class="check">查看</span>
<span class="stop">终止</span>
<span class="change">变更</span>
</td>
</tr>
</tbody>
</table>
3 自定义表格样式
直接选中标签,然后调整样式即可
.content .inner_c .ordered-info .list table thead{
background-color: #337AB7;
color: #FFFFEF;
font-size: 18px;
}
.content .inner_c .ordered-info .list table span{
padding: 0 4px;
}
.content .inner_c .ordered-info .list table .dealing{
display:inline-block;
height: 20px;
font-size: 13px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
background-color: #4482FF;
color:#FFFFEF;
}
.content .inner_c .ordered-info .list table .normal_use{
display:inline-block;
height: 20px;
font-size: 13px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
background-color: #36B37E;
color:#FFFFEF;
}
.content .inner_c .ordered-info .list table .check{
display:inline-block;
height: 20px;
font-size: 13px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
background-color: #F39C12;
color:#FFFFEF;
}
.content .inner_c .ordered-info .list table .stop{
display:inline-block;
height: 20px;
font-size: 13px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
background-color: #F75765;
color:#FFFFEF;
}
.content .inner_c .ordered-info .list table .change{
display:inline-block;
height: 20px;
font-size: 13px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
background-color: #B067E6;
color:#FFFFEF;
}
4 遇到的问题
在写页面上半部分时,自己用的盒模型是标准盒模型即content-box,在引入bootstrap后发现上面写的都乱了,原因是bootstrap采用border-box模型(此时padding不会影响最终宽度的计算),但我之前都是content-box,padding参与了计算,改变模型后由于宽度不够就导致有些内容被挤下来了,如下图企业信息板块
解决方法是让自己之前写的样式权重最高,在自己写的css中添加样式如下:
解决好上面问题后,又出现一个新问题,经查找,原来是p标签在作怪,引入的文件里面自带了p标签的样式,如下图所示:
解决方法:重写p标签样式,覆盖掉文件带来的样式,如下:
修改好后整个页面就都好了,右上角的小图标也正常了,哈哈哈!