3.4.2 带背景条纹的表格
背景条纹表格,就是在现有.table样式的基础上再应用一个.table-striped样式,其添加了隔行加背景色的设置。使用方式如下:
- <table class="table table-striped">
- ...
- </table>
运行效果如图3-13所示。
图3-13 条纹背景表格的运行效果
隔行换色的实现方式是利用了CSS 3里的: nth-child选择器来实现的,所以不支持IE 8及以下版本。源码如下:
- // 源码1464行
- .table-striped > tbody > tr:nth-child(odd) > td,
- .table-striped > tbody > tr:nth-child(odd) > th {
- background-color: #f9f9f9;
- /* 如果需要更换颜色,需要重载覆盖才行(详情阅读第2章的2.3节组件架构) */
- }