Bootstrap表格

摘要:
前面的话表格是Bootstrap的一个基础组件之一,Bootstrap为表格提供了1种基础样式和4种附加样式以及1个支持响应式的表格。在Bootstrap中实现这种表格效果并不困难,只需要在的基础上增加类名“.table-striped”即可通过.table-striped类可以给之内的每一行增加斑马条纹样式。

前面的话

表格是Bootstrap的一个基础组件之一,Bootstrap为表格提供了1种基础样式4种附加样式以及1个支持响应式的表格。在使用Bootstrap的表格过程中,只需要添加对应的类名就可以得到不同的表格风格,本文将详细介绍Boostrap表格

基本实例

Boostrap将表格<table>的样式重置如下

table {
    background-color: transparent;
    border-spacing: 0;
    border-collapse: collapse;
}
<table>
  <caption>Optional table caption.</caption>
  <thead>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>    

为任意<table>标签添加.table类可以为其赋予基本的样式—少量的内边距(padding)和水平方向的分隔线

“.table”主要有三个作用:

☑ 给表格设置了margin-bottom:20px以及设置单元内距

☑ 在thead底部设置了一个2px的浅灰实线

☑ 每个单元格顶部设置了一个1px的浅灰实线

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

条纹状表格

有时候为了让表格更具阅读性,需要将表格制作成类似于斑马线的效果。简单点说就是让表格带有背景条纹效果。在Bootstrap中实现这种表格效果并不困难,只需要在<table class="table">的基础上增加类名“.table-striped”即可

通过.table-striped类可以给<tbody>之内的每一行增加斑马条纹样式。其效果与基础表格相比,仅是在tbody隔行有一个浅灰色的背景色

[注意]条纹状表格是依赖:nth-childCSS 选择器实现的,而这一功能不被IE8-支持

.table-striped > tbody > tr:nth-of-type(odd) {
    background-color: #f9f9f9;
}
<table class="table table-striped">
  ...
</table>

带边框表格

基础表格仅让表格部分地方有边框,但有时候需要整个表格具有边框效果。Bootstrap出于实际运用,也考虑这种表格效果,即所有单元格具有一条1px的边框

Bootstrap中带边框的表格使用方法和斑马线表格的使用方法类似,只需要在基础表格<table class="table">基础上添加一个“.table-bordered”类名即可

添加.table-bordered类为表格和其中的每个单元格增加边框

<table class="table table-bordered">
  ...
</table>

鼠标悬停

当鼠标悬停在表格的行上面有一个高亮的背景色,这样可以时刻告诉用户正在阅读表格哪一行的数据

通过添加 .table-hover 类可以让 <tbody> 中的每一行对鼠标悬停状态作出响应

<table class="table table-hover">
  ...
</table>
.table-hover > tbody > tr:hover {
    background-color: #f5f5f5;
}

紧缩表格

紧凑型表格,或者叫紧缩表格,简单理解,就是单元格没内边距或者内边距较其他表格的内边距更小。换句话说,要实现紧凑型表格只需要重置表格单元格的内边距padding的值

通过添加 .table-condensed 类可以让表格更加紧凑,单元格中的内补(padding)均会减半

<table class="table table-condensed">
  ...
</table>

状态类

通过这些状态类可以为行或单元格设置颜色

Bootstrap表格第1张
<table class="table">
  <thead>
    <tr>
      <th>#</th>
      <th>Column heading</th>
      <th>Column heading</th>
      <th>Column heading</th>
    </tr>
  </thead>
  <tbody>
    <tr class="active">
      <th scope="row">1</th>
      <td>Column content</td>
      <td>Column content</td>
      <td>Column content</td>
    </tr>
    <tr class="success">
      <th scope="row">2</th>
      <td>Column content</td>
      <td>Column content</td>
      <td>Column content</td>
    </tr>
    <tr class="info">
      <th scope="row">3</th>
      <td>Column content</td>
      <td>Column content</td>
      <td>Column content</td>
    </tr>
    <tr class="warning">
      <th scope="row">4</th>
      <td>Column content</td>
      <td>Column content</td>
      <td>Column content</td>
    </tr>
    <tr class="danger">
      <th scope="row">5</th>
      <td>Column content</td>
      <td>Column content</td>
      <td>Column content</td>
    </tr>
    <tr>
      <th scope="row">6</th>
      <td>Column content</td>
      <td>Column content</td>
      <td>Column content</td>
    </tr>
  </tbody>
</table>

响应式表格

将任何 .table 元素包裹在 .table-responsive 元素内,即可创建响应式表格,其会在小屏幕设备上(小于768px)水平滚动。当屏幕大于 768px 宽度时,水平滚动条消失

<div class="table-responsive">
  <table class="table">
    <thead>
      <tr>
        <th>#</th>
        <th>Table heading</th>
        <th>Table heading</th>
        <th>Table heading</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">1</th>
        <td>Table cell</td>
        <td>Table cell</td>
        <td>Table cell</td>
      </tr>
      <tr>
        <th scope="row">2</th>
        <td>Table cell</td>
        <td>Table cell</td>
        <td>Table cell</td>
      </tr>
      <tr>
        <th scope="row">3</th>
        <td>Table cell</td>
        <td>Table cell</td>
        <td>Table cell</td>
      </tr>
    </tbody>
  </table>
</div>

免责声明:文章转载自《Bootstrap表格》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇011-MAC 设置环境变量path的几种方法JQ之$.ajax()方法以及ajax跨域请求下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

快速抽取Oracle数据到Mongo

以下是本人从oralce抽取数据到Mongol的方法,也没来得及整理,基本使用方法都是复制其他博主的,希望对大家有用。 step1 利用sqluldr2快速导出CSV格式数据 Oracle使用sqluldr2原创乘风晓栈 最后发布于2018-11-01 15:55:01 阅读数 9260 收藏展开分三部分: 1 . sqluldr2简介与使用 2 . sq...

(转)HBase 常用Shell命令

转自:http://my.oschina.net/u/189445/blog/595232 hbase shell命令 描述 alter 修改列族(column family)模式 count 统计表中行的数量 create 创建表 describe 显示表相关的详细信息 delete 删除指定对象的值(可以为表,行,列对应的值,...

html5中不再支持table的cellspacing和cellpadding属性

如果你现在开始用html5的声明来写页面时,你会发现在定义table的cellspacing和cellpadding时被提示该属性已过时或者提示非法属性。具体原因是在html5中table标签的这两个属性已经被移除,需要定义边框之类的时应该使用css的写法。 具体实现如下: <!DOCTYPE html> <html xmlns="htt...

SQLi-Labs:Less54-Less65

从54关开始,开始慢慢偏向于实际环境,加了次数限制之类的 Less 54 本关中是对输入的次数做了限制,必须在10次请求之内获取信息,否则会刷新表名 首先判断了单引号闭合 ?id=1'  判断有三列 ?id=1' order by 3--+  爆库 ?id=-1' union select 1,database(),3--+   爆表 ?id=-1'...

ASP操作Excel技术总结

目录一、环境配置二、ASP对Excel的基本操作三、ASP操作Excel生成数据表四、ASP操作Excel生成Chart图五、服务器端Excel文件浏览、下载、删除方案六、附录正文一、环境配置服务器端的环境配置从参考资料上看,微软系列的配置应该都行,即:1.Win9x+PWS+Office2.Win2000Professional+PWS+Office3....

db2 reorg详解

reorgchk,检查table index 是否需要重组。reorg 重组,重新放置数据位置。runstats 统计信息,可以优化查询器 一个完整的日常维护规范可以帮助 DBA 理顺每天需要的操作,以便更好的监控和维护数据库,保证数据库的正常、安全、高效运行,防止一些错误重复发生。 由于DB2使用CBO作为数据库的优化器,数据库对象的状态信息对数据库使用...