全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

Bootstrap CSS布局之表格

表格组件中,BootStrap提供了
1种基础.table样式
4种附加样式(.table-striped/.table-bordered/.table-hover/.table-condensed)
1种支持响应式布局的.table-responsive

table样式

//源码
table {
 background-color: transparent;
}
caption {
 padding-top: 8px;
 padding-bottom: 8px;
 color: #777;
 text-align: left;
}
th {
 text-align: left;
}
.table {
 width: 100%;
 max-width: 100%;
 margin-bottom: 20px;
}
.table > thead > tr > th,
.table > tbody > tr > th,
.table > tfoot > tr > th,
.table > thead > tr > td,
.table > tbody > tr > td,
.table > tfoot > tr > td {
 padding: 8px;
 line-height: 1.42857143;
 vertical-align: top;
 border-top: 1px solid #ddd;
}
.table > thead > tr > th {
 vertical-align: bottom;
 border-bottom: 2px solid #ddd;
}
.table > caption + thead > tr:first-child > th,
.table > colgroup + thead > tr:first-child > th,
.table > thead:first-child > tr:first-child > th,
.table > caption + thead > tr:first-child > td,
.table > colgroup + thead > tr:first-child > td,
.table > thead:first-child > tr:first-child > td {
 border-top: 0;
}
.table > tbody + tbody {
 border-top: 2px solid #ddd;
}
.table .table {
 background-color: #fff;
}

table.striped样式–带背景条纹的表格

//源码
.table-striped > tbody > tr:nth-of-type(odd) {
 background-color: #f9f9f9;
}

table.bordered样式–带边框的表格

为表格所有的单元格提供1条1像素宽的边框

//源码
.table-bordered {
 border: 1px solid #ddd;
}
.table-bordered > thead > tr > th,
.table-bordered > tbody > tr > th,
.table-bordered > tfoot > tr > th,
.table-bordered > thead > tr > td,
.table-bordered > tbody > tr > td,
.table-bordered > tfoot > tr > td {
 border: 1px solid #ddd;
}
.table-bordered > thead > tr > th,
.table-bordered > thead > tr > td {
 border-bottom-width: 2px;
}

table.hover样式–鼠标悬停高亮的表格

table.condensed样式–紧凑型的表格

//源码
.table-condensed > thead > tr > th,
.table-condensed > tbody > tr > th,
.table-condensed > tfoot > tr > th,
.table-condensed > thead > tr > td,
.table-condensed > tbody > tr > td,
.table-condensed > tfoot > tr > td {
 padding: 5px;
}

行级元素样式

Bootstrap为表格的tr元素提供了5种额外的样式,用于控制tr的背景颜色。active、success、info、warning、danger

//源码
.table > thead > tr > td.active,
.table > tbody > tr > td.active,
.table > tfoot > tr > td.active,
.table > thead > tr > th.active,
.table > tbody > tr > th.active,
.table > tfoot > tr > th.active,
.table > thead > tr.active > td,
.table > tbody > tr.active > td,
.table > tfoot > tr.active > td,
.table > thead > tr.active > th,
.table > tbody > tr.active > th,
.table > tfoot > tr.active > th {
 background-color: #f5f5f5;
}
.table-hover > tbody > tr > td.active:hover,
.table-hover > tbody > tr > th.active:hover,
.table-hover > tbody > tr.active:hover > td,
.table-hover > tbody > tr:hover > .active,
.table-hover > tbody > tr.active:hover > th {
 background-color: #e8e8e8;
}
.table > thead > tr > td.success,
.table > tbody > tr > td.success,
.table > tfoot > tr > td.success,
.table > thead > tr > th.success,
.table > tbody > tr > th.success,
.table > tfoot > tr > th.success,
.table > thead > tr.success > td,
.table > tbody > tr.success > td,
.table > tfoot > tr.success > td,
.table > thead > tr.success > th,
.table > tbody > tr.success > th,
.table > tfoot > tr.success > th {
 background-color: #dff0d8;
}
.table-hover > tbody > tr > td.success:hover,
.table-hover > tbody > tr > th.success:hover,
.table-hover > tbody > tr.success:hover > td,
.table-hover > tbody > tr:hover > .success,
.table-hover > tbody > tr.success:hover > th {
 background-color: #d0e9c6;
}
.table > thead > tr > td.info,
.table > tbody > tr > td.info,
.table > tfoot > tr > td.info,
.table > thead > tr > th.info,
.table > tbody > tr > th.info,
.table > tfoot > tr > th.info,
.table > thead > tr.info > td,
.table > tbody > tr.info > td,
.table > tfoot > tr.info > td,
.table > thead > tr.info > th,
.table > tbody > tr.info > th,
.table > tfoot > tr.info > th {
 background-color: #d9edf7;
}
.table-hover > tbody > tr > td.info:hover,
.table-hover > tbody > tr > th.info:hover,
.table-hover > tbody > tr.info:hover > td,
.table-hover > tbody > tr:hover > .info,
.table-hover > tbody > tr.info:hover > th {
 background-color: #c4e3f3;
}
.table > thead > tr > td.warning,
.table > tbody > tr > td.warning,
.table > tfoot > tr > td.warning,
.table > thead > tr > th.warning,
.table > tbody > tr > th.warning,
.table > tfoot > tr > th.warning,
.table > thead > tr.warning > td,
.table > tbody > tr.warning > td,
.table > tfoot > tr.warning > td,
.table > thead > tr.warning > th,
.table > tbody > tr.warning > th,
.table > tfoot > tr.warning > th {
 background-color: #fcf8e3;
}
.table-hover > tbody > tr > td.warning:hover,
.table-hover > tbody > tr > th.warning:hover,
.table-hover > tbody > tr.warning:hover > td,
.table-hover > tbody > tr:hover > .warning,
.table-hover > tbody > tr.warning:hover > th {
 background-color: #faf2cc;
}
.table > thead > tr > td.danger,
.table > tbody > tr > td.danger,
.table > tfoot > tr > td.danger,
.table > thead > tr > th.danger,
.table > tbody > tr > th.danger,
.table > tfoot > tr > th.danger,
.table > thead > tr.danger > td,
.table > tbody > tr.danger > td,
.table > tfoot > tr.danger > td,
.table > thead > tr.danger > th,
.table > tbody > tr.danger > th,
.table > tfoot > tr.danger > th {
 background-color: #f2dede;
}
.table-hover > tbody > tr > td.danger:hover,
.table-hover > tbody > tr > th.danger:hover,
.table-hover > tbody > tr.danger:hover > td,
.table-hover > tbody > tr:hover > .danger,
.table-hover > tbody > tr.danger:hover > th {
 background-color: #ebcccc;
}

响应式表格

随着响应式设计的大量需求,Bootstrap为表格提供了一个响应式设计的容器(.table-responsive),将.table-responsive样式包装在.table样式外部即可创建响应式表格
在小屏幕(<768px)水平滚动,大屏幕上水平滚动条消失

<div class="table-responsive">
 <table class="table">
 </table>
</div>

//源码
.table-responsive {
 min-height: .01%;
 overflow-x: auto;
}
//把原有.table样式得底部外边距margin-bottom从20px改成了0px,目的是消除滚动条带来的上下高度差
//并在.table-responsive样式上设置了一个margin-bottom:15px,避免和容器外部的下一个元素重叠
@media screen and (max-width: 767px) {
 .table-responsive {
 width: 100%;
 margin-bottom: 15px;
 overflow-y: hidden;
 -ms-overflow-style: -ms-autohiding-scrollbar;
 border: 1px solid #ddd;
 }
 .table-responsive > .table {
 margin-bottom: 0;
 }
 .table-responsive > .table > thead > tr > th,
 .table-responsive > .table > tbody > tr > th,
 .table-responsive > .table > tfoot > tr > th,
 .table-responsive > .table > thead > tr > td,
 .table-responsive > .table > tbody > tr > td,
 .table-responsive > .table > tfoot > tr > td {
 white-space: nowrap;
 }
 .table-responsive > .table-bordered {
 border: 0;
 }
 //可以看到table-responsive给自己加了一个1px的外边框,如果在table上在使用table-bordered样式得话,就会和表格的外边框重合,就会变粗,所以进行了以下代码的编写
 .table-responsive > .table-bordered > thead > tr > th:first-child,
 .table-responsive > .table-bordered > tbody > tr > th:first-child,
 .table-responsive > .table-bordered > tfoot > tr > th:first-child,
 .table-responsive > .table-bordered > thead > tr > td:first-child,
 .table-responsive > .table-bordered > tbody > tr > td:first-child,
 .table-responsive > .table-bordered > tfoot > tr > td:first-child {
 border-left: 0;//所有tr的第一个单元格(最左边的一列)的左边框设置为0px
 }
 .table-responsive > .table-bordered > thead > tr > th:last-child,
 .table-responsive > .table-bordered > tbody > tr > th:last-child,
 .table-responsive > .table-bordered > tfoot > tr > th:last-child,
 .table-responsive > .table-bordered > thead > tr > td:last-child,
 .table-responsive > .table-bordered > tbody > tr > td:last-child,
 .table-responsive > .table-bordered > tfoot > tr > td:last-child {
 border-right: 0;//所有tr的最后一个单元格(最右边的一列)的左边框设置为0px
 }
 .table-responsive > .table-bordered > tbody > tr:last-child > th,
 .table-responsive > .table-bordered > tfoot > tr:last-child > th,
 .table-responsive > .table-bordered > tbody > tr:last-child > td,
 .table-responsive > .table-bordered > tfoot > tr:last-child > td {
 border-bottom: 0;//最后一行tr里的单元格的底部边框设置为0px
 }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# Bootstrap  # CSS布局  # 表格  # JS表格组件神器bootstrap table详解(基础版)  # Angular.js与Bootstrap相结合实现表格分页代码  # JS组件Bootstrap Table表格行拖拽效果实现代码  # BootStrap和jQuery相结合实现可编辑表格  # JS组件Bootstrap Table表格多行拖拽效果实现代码  # BootStrap table表格插件自适应固定表头(超好用)  # 基于Bootstrap使用jQuery实现简单可编辑表格  # 值得分享的轻量级Bootstrap Table表格插件  # 基于Bootstrap3表格插件和分页插件实例详解  # JS表格组件神器bootstrap table详解(强化版)  # 单元格  # 设置为  # 就会  # 滚动条  # 第一个  # 鼠标  # 并在  # 给自己  # 可以看到  # 装在  # 大家多多  # 进行了  # 改成了  # 目的是  # thead  # tfoot  # tbody  # tr  # left  # max 


相关文章: 如何高效配置IIS服务器搭建网站?  用v-html解决Vue.js渲染中html标签不被解析的问题  如何通过可视化优化提升建站效果?  怎么制作一个起泡网,水泡粪全漏粪育肥舍冬季氨气超过25ppm,可以有哪些措施降低舍内氨气水平?  Avalonia如何实现跨窗口通信 Avalonia窗口间数据传递  整人网站在线制作软件,整蛊网站退不出去必须要打我是白痴才能出去?  C#怎么使用委托和事件 C# delegate与event编程方法  建站168自助建站系统:快速模板定制与SEO优化指南  如何快速打造个性化非模板自助建站?  ,sp开头的版面叫什么?  家庭建站与云服务器建站,如何选择更优?  内网网站制作软件,内网的网站如何发布到外网?  建站之星后台密码遗忘如何找回?  西安制作网站公司有哪些,西安货运司机用的最多的app或者网站是什么?  网站制作公司广州有几家,广州尚艺美发学校网站是多少?  html制作网站的步骤有哪些,iapp如何添加网页?  如何做静态网页,sublimetext3.0制作静态网页?  c# 服务器GC和工作站GC的区别和设置  网页制作模板网站推荐,网页设计海报之类的素材哪里好?  如何在Mac上搭建Golang开发环境_使用Homebrew安装和管理Go版本  安徽网站建设与外贸建站服务专业定制方案  广州顶尖建站服务:企业官网建设与SEO优化一体化方案  北京专业网站制作设计师招聘,北京白云观官方网站?  微信小程序 五星评分(包括半颗星评分)实例代码  如何在IIS中新建站点并解决端口绑定冲突?  已有域名和空间如何快速搭建网站?  如何通过万网虚拟主机快速搭建网站?  制作公司内部网站有哪些,内网如何建网站?  详解免费开源的DotNet二维码操作组件ThoughtWorks.QRCode(.NET组件介绍之四)  昆明网站制作哪家好,昆明公租房申请网上登录入口?  建站之星如何一键生成手机站?  ,交易猫的商品怎么发布到网站上去?  如何在Windows环境下新建FTP站点并设置权限?  建站之星安装提示数据库无法连接如何解决?  如何快速搭建高效WAP手机网站?  网站插件制作软件免费下载,网页视频怎么下到本地插件?  SAX解析器是什么,它与DOM在处理大型XML文件时有何不同?  ,怎么用自己头像做动态表情包?  网站制作价目表怎么做,珍爱网婚介费用多少?  如何在企业微信快速生成手机电脑官网?  建站之星代理平台如何选择最佳方案?  如何设计高效校园网站?  宝塔面板创建网站无法访问?如何快速排查修复?  建站主机如何安装配置?新手必看操作指南  宝塔面板如何快速创建新站点?  临沂网站制作企业,临沂第三中学官方网站?  如何续费美橙建站之星域名及服务?  如何挑选优质建站一级代理提升网站排名?  如何设置并定期更换建站之星安全管理员密码?  建站之星如何实现PC+手机+微信网站五合一建站? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。