本文转自:http://elvery.net/demo/responsive-tables/

A quick and dirty look at some techniques for designing responsive table layouts. This was put together in haste (and with the aid of Twitter Bootstrap) for What Do You Know Brisbane hosted by Web Directions.

I work for a really great little web design agency in Brisbane, and you should say hello.

The Unseen Column

This technique, first described by Stuart Curry (@irishstu) involves simply hiding less important columns on smaller screen sizes.

Example

Code Company Price Change Change % Open High Low Volume
AAC AUSTRALIAN AGRICULTURAL COMPANY LIMITED. $1.38 -0.01 -0.36% $1.39 $1.39 $1.38 9,395
AAD ARDENT LEISURE GROUP $1.15   +0.02 1.32% $1.14 $1.15 $1.13 56,431
AAX AUSENCO LIMITED $4.00 -0.04 -0.99% $4.01 $4.05 $4.00 90,641
ABC ADELAIDE BRIGHTON LIMITED $3.00   +0.06 2.04% $2.98 $3.00 $2.96 862,518
ABP ABACUS PROPERTY GROUP $1.91 0.00 0.00% $1.92 $1.93 $1.90 595,701
ABY ADITYA BIRLA MINERALS LIMITED $0.77   +0.02 2.00% $0.76 $0.77 $0.76 54,567
ACR ACRUX LIMITED $3.71   +0.01 0.14% $3.70 $3.72 $3.68 191,373
ADU ADAMUS RESOURCES LIMITED $0.72 0.00 0.00% $0.73 $0.74 $0.72 8,602,291
AGG ANGLOGOLD ASHANTI LIMITED $7.81 -0.22 -2.74% $7.82 $7.82 $7.81 148
AGK AGL ENERGY LIMITED $13.82   +0.02 0.14% $13.83 $13.83 $13.67 846,403
AGO ATLAS IRON LIMITED $3.17 -0.02 -0.47% $3.11 $3.22 $3.10 5,416,303

Code

The approach I've presented here assumes you know the index of the columns to be hidden. This probably isn't always appropriate, and isn't all that semantic. Another option is to give the <th> and <td> classes based on importance level and code your CSS accordingly.

  1. <table>
  2. <thead>
  3. <tr>
  4. <th>Code</th>
  5. <th>Company</th>
  6. <th class="numeric">Price</th>
  7. <th class="numeric">Change</th>
  8. <th class="numeric">Change %</th>
  9. <th class="numeric">Open</th>
  10. <th class="numeric">High</th>
  11. <th class="numeric">Low</th>
  12. <th class="numeric">Volume</th>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr>
  17. <td>AAC</td>
  18. <td>AUSTRALIAN AGRICULTURAL COMPANY LIMITED.</td>
  19. <td class="numeric">$1.38</td>
  20. <td class="numeric">-0.01</td>
  21. <td class="numeric">-0.36%</td>
  22. <td class="numeric">$1.39</td>
  23. <td class="numeric">$1.39</td>
  24. <td class="numeric">$1.38</td>
  25. <td class="numeric">9,395</td>
  26. </tr>
  27. </tbody>
  28. </table>
  1. @media only screen and (max-width: 800px) {
  2. #unseen table td:nth-child(2),
  3. #unseen table th:nth-child(2) {display: none;}
  4. }
  5. @media only screen and (max-width: 640px) {
  6. #unseen table td:nth-child(4),
  7. #unseen table th:nth-child(4),
  8. #unseen table td:nth-child(7),
  9. #unseen table th:nth-child(7),
  10. #unseen table td:nth-child(8),
  11. #unseen table th:nth-child(8){display: none;}
  12. }

Flip Scroll

This technique was first published by David Bushell (@dbushell). For the full low down on this technique visit his post on the technique, Responsive Tables (2). While you're there, it's also worth checking out his responsive calendar proof of concept.

Example

Code Company Price Change Change % Open High Low Volume
AAC AUSTRALIAN AGRICULTURAL COMPANY LIMITED. $1.38 -0.01 -0.36% $1.39 $1.39 $1.38 9,395
AAD ARDENT LEISURE GROUP $1.15   +0.02 1.32% $1.14 $1.15 $1.13 56,431
AAX AUSENCO LIMITED $4.00 -0.04 -0.99% $4.01 $4.05 $4.00 90,641
ABC ADELAIDE BRIGHTON LIMITED $3.00   +0.06 2.04% $2.98 $3.00 $2.96 862,518
ABP ABACUS PROPERTY GROUP $1.91 0.00 0.00% $1.92 $1.93 $1.90 595,701
ABY ADITYA BIRLA MINERALS LIMITED $0.77   +0.02 2.00% $0.76 $0.77 $0.76 54,567
ACR ACRUX LIMITED $3.71   +0.01 0.14% $3.70 $3.72 $3.68 191,373
ADU ADAMUS RESOURCES LIMITED $0.72 0.00 0.00% $0.73 $0.74 $0.72 8,602,291
AGG ANGLOGOLD ASHANTI LIMITED $7.81 -0.22 -2.74% $7.82 $7.82 $7.81 148
AGK AGL ENERGY LIMITED $13.82   +0.02 0.14% $13.83 $13.83 $13.67 846,403
AGO ATLAS IRON LIMITED $3.17 -0.02 -0.47% $3.11 $3.22 $3.10 5,416,303

Code

The biggest trick to getting this working is to use display: inline-block; on the table rows and white-space: nowrap; on the table body. You'll also need to make use of your favourite float clearing method.

  1. <table>
  2. <thead>
  3. <tr>
  4. <th>Code</th>
  5. <th>Company</th>
  6. <th class="numeric">Price</th>
  7. <th class="numeric">Change</th>
  8. <th class="numeric">Change %</th>
  9. <th class="numeric">Open</th>
  10. <th class="numeric">High</th>
  11. <th class="numeric">Low</th>
  12. <th class="numeric">Volume</th>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr>
  17. <td>AAC</td>
  18. <td>AUSTRALIAN AGRICULTURAL COMPANY LIMITED.</td>
  19. <td class="numeric">$1.38</td>
  20. <td class="numeric">-0.01</td>
  21. <td class="numeric">-0.36%</td>
  22. <td class="numeric">$1.39</td>
  23. <td class="numeric">$1.39</td>
  24. <td class="numeric">$1.38</td>
  25. <td class="numeric">9,395</td>
  26. </tr>
  27. </tbody>
  28. </table>
  1. @media only screen and (max-width: 800px) {
  2. #flip-scroll .cf:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
  3. #flip-scroll * html .cf { zoom: 1; }
  4. #flip-scroll *:first-child+html .cf { zoom: 1; }
  5. #flip-scroll table { width: 100%; border-collapse: collapse; border-spacing: 0; }
  6. #flip-scroll th,
  7. #flip-scroll td { margin: 0; vertical-align: top; }
  8. #flip-scroll th { text-align: left; }
  9. #flip-scroll table { display: block; position: relative; width: 100%; }
  10. #flip-scroll thead { display: block; float: left; }
  11. #flip-scroll tbody { display: block; width: auto; position: relative; overflow-x: auto; white-space: nowrap; }
  12. #flip-scroll thead tr { display: block; }
  13. #flip-scroll th { display: block; text-align: right; }
  14. #flip-scroll tbody tr { display: inline-block; vertical-align: top; }
  15. #flip-scroll td { display: block; min-height: 1.25em; text-align: left; }
  16. /* sort out borders */
  17. #flip-scroll th { border-bottom: 0; border-left: 0; }
  18. #flip-scroll td { border-left: 0; border-right: 0; border-bottom: 0; }
  19. #flip-scroll tbody tr { border-left: 1px solid #babcbf; }
  20. #flip-scroll th:last-child,
  21. #flip-scroll td:last-child { border-bottom: 1px solid #babcbf; }
  22. }

No More Tables

This technique was developed by Chris Coyier (@chriscoyier) and described in his post Responsive Data Tables at css-tricks.com. While you're there, you should probably check out the Responsive Tables Roundup post, which showcases all these techniques and more.

Example

Code Company Price Change Change % Open High Low Volume
AAC AUSTRALIAN AGRICULTURAL COMPANY LIMITED. $1.38 -0.01 -0.36% $1.39 $1.39 $1.38 9,395
AAD ARDENT LEISURE GROUP $1.15   +0.02 1.32% $1.14 $1.15 $1.13 56,431
AAX AUSENCO LIMITED $4.00 -0.04 -0.99% $4.01 $4.05 $4.00 90,641
ABC ADELAIDE BRIGHTON LIMITED $3.00   +0.06 2.04% $2.98 $3.00 $2.96 862,518
ABP ABACUS PROPERTY GROUP $1.91 0.00 0.00% $1.92 $1.93 $1.90 595,701
ABY ADITYA BIRLA MINERALS LIMITED $0.77   +0.02 2.00% $0.76 $0.77 $0.76 54,567
ACR ACRUX LIMITED $3.71   +0.01 0.14% $3.70 $3.72 $3.68 191,373
ADU ADAMUS RESOURCES LIMITED $0.72 0.00 0.00% $0.73 $0.74 $0.72 8,602,291
AGG ANGLOGOLD ASHANTI LIMITED $7.81 -0.22 -2.74% $7.82 $7.82 $7.81 148
AGK AGL ENERGY LIMITED $13.82   +0.02 0.14% $13.83 $13.83 $13.67 846,403
AGO ATLAS IRON LIMITED $3.17 -0.02 -0.47% $3.11 $3.22 $3.10 5,416,303

Code

This technique as presented here relies on using HTML5 data attributes and accessing them via CSS to specify the column headings. The other option is to hard code the column headings into the CSS, but as we all know content in CSS is a huge no-no.

  1. <table>
  2. <thead>
  3. <tr>
  4. <th>Code</th>
  5. <th>Company</th>
  6. <th class="numeric">Price</th>
  7. <th class="numeric">Change</th>
  8. <th class="numeric">Change %</th>
  9. <th class="numeric">Open</th>
  10. <th class="numeric">High</th>
  11. <th class="numeric">Low</th>
  12. <th class="numeric">Volume</th>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr>
  17. <td data-title="Code">AAC</td>
  18. <td data-title="Company">AUSTRALIAN AGRICULTURAL COMPANY LIMITED.</td>
  19. <td data-title="Price" class="numeric">$1.38</td>
  20. <td data-title="Change" class="numeric">-0.01</td>
  21. <td data-title="Change %" class="numeric">-0.36%</td>
  22. <td data-title="Open" class="numeric">$1.39</td>
  23. <td data-title="High" class="numeric">$1.39</td>
  24. <td data-title="Low" class="numeric">$1.38</td>
  25. <td data-title="Volume" class="numeric">9,395</td>
  26. </tr>
  27. </tbody>
  28. </table>
  1. @media only screen and (max-width: 800px) {
  2. /* Force table to not be like tables anymore */
  3. #no-more-tables table,
  4. #no-more-tables thead,
  5. #no-more-tables tbody,
  6. #no-more-tables th,
  7. #no-more-tables td,
  8. #no-more-tables tr {
  9. display: block;
  10. }
  11. /* Hide table headers (but not display: none;, for accessibility) */
  12. #no-more-tables thead tr {
  13. position: absolute;
  14. top: -9999px;
  15. left: -9999px;
  16. }
  17. #no-more-tables tr { border: 1px solid #ccc; }
  18. #no-more-tables td {
  19. /* Behave like a "row" */
  20. border: none;
  21. border-bottom: 1px solid #eee;
  22. position: relative;
  23. padding-left: 50%;
  24. white-space: normal;
  25. text-align:left;
  26. }
  27. #no-more-tables td:before {
  28. /* Now like a table header */
  29. position: absolute;
  30. /* Top/left values mimic padding */
  31. top: 6px;
  32. left: 6px;
  33. width: 45%;
  34. padding-right: 10px;
  35. white-space: nowrap;
  36. text-align:left;
  37. font-weight: bold;
  38. }
  39. /*
  40. Label the data
  41. */
  42. #no-more-tables td:before { content: attr(data-title); }
  43. }

[转]Responsive Tables Demo的更多相关文章

  1. [转]响应式表格jQuery插件 – Responsive tables

    本文转自:http://www.shejidaren.com/responsive-tables-for-bootstrap-3.html 这个Responsive tables jQuery插件依赖 ...

  2. responsive tables

    以上内容原本是整理为ppt格式的,贴过来格式有点乱,请见谅. 其他responsive tables参考: http://gergeo.se/RWD-Table-Patterns/ 3种类型的代码参考 ...

  3. Frontend Development

    原文链接: https://github.com/dypsilon/frontend-dev-bookmarks Frontend Development Looking for something ...

  4. IOS开发--UI进阶之iCarousel学习(待翻译)

    前言:先展示这个会被多个项目用到的开源的轮播器的其中一个动画效果: 更多的效果请到github原网址查看:https://github.com/nicklockwood/iCarousel 源码也可以 ...

  5. .Net程序员学用Oracle系列(19):我知道的导出和导入

    1.传统的导出/导入工具 1.1.EXP 命令详解 1.2.IMP 命令详解 1.3.EXP/IMP 使用技巧 2.新的导出/导入工具 2.1.EXPDP/IMPDP 参数说明 2.2.EXPDP/I ...

  6. .Net程序员学用Oracle系列(19):导出、导入(备份、还原)

    1.传统的导出/导入工具 1.1.EXP 命令详解 1.2.IMP 命令详解 1.3.EXP/IMP 使用技巧 2.新的导出/导入工具 2.1.EXPDP/IMPDP 参数说明 2.2.EXPDP/I ...

  7. 使用Bootstrap 基于MVC输出移动化table 列表

    基于Bootrap的列表组及栅格布局来实现 模型定义 public class StreetEvent { public int Id { get; set; } public string Stre ...

  8. 容器,表格 ,div,元素可左右拖动,滚动 css

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  9. amazeui学习笔记--css(HTML元素5)--表格Table

    amazeui学习笔记--css(HTML元素5)--表格Table 一.总结 1.基本样式:am-table:直接模块名  <table class="am-table"& ...

随机推荐

  1. 简单介绍.Net3.0 中跨线程访问控件

    这两天用WPF做一个项目的UI部分时,发现跨线程地访问了UI控件,自然地报异常了.当时找了半天也没在控件中找到InvokeRequired属性和Invoke方法,郁闷之极.....最后发现在.net3 ...

  2. foreach---集合已修改;可能无法执行枚举操作。

    小结 : foreach是取只读的,在取的时候数据不能变(包括修改,删除,添加等).要避免这个问题,就应该使用for循环--- 原因: 当用foreach遍历Collection时,如果对Collec ...

  3. oracle client ORA-12541: TNS: 无监听程序

    1. Question description: if you are setting the oracle client to add a local network service,  you m ...

  4. 【洛谷 p3374】模板-树状数组 1(数据结构)

    题目:已知一个数列,你需要进行下面两种操作:1.将某一个数加上x:2.求出某区间每一个数的和. 解法:树状数组求前缀和. #include<cstdio> #include<cstd ...

  5. C# on Visual Studio Code

    installation Download .NET Core SDK installer and install it. https://www.microsoft.com/net/download ...

  6. PHP KMP算法实现

    function getNext( $str ){ $ret = array(0=>0); for( $j =1; $j < strlen($str); $j++ ){ $_s = sub ...

  7. Win10的分辨率问题

    个人觉得win10扁平化的界面给人全新的感觉,但安装后,发现分辨率只有1280x720.1152x864.1024x768(推荐).800x600,不管调整哪一个,都觉得分辨率还是有问题,看起来字体. ...

  8. Atitit. Atiposter 发帖机 新特性 poster new feature   v7 q39

    Atitit. Atiposter 发帖机 新特性 poster new feature   v7 q39 V1  初步实现sina csdn cnblogs V2  实现qzone sohu 的发帖 ...

  9. 详解Paint的setPathEffect(PathEffect effect)

    一.setPathEffect() 这个方法一看就和path有关,顾名思义,它就是给path设置样式(效果)的.PathEffect这个路径效果类没有具体的实现,效果是由它的六个子类实现的: 这六个子 ...

  10. object-c中的类目,延展,协议

    协议 协议只有方法的声明(类似于其他编程语言的接口)   协议相当于大家都所遵循的 关键字 @protocol 协议名 <所遵循的协议> 默认NSObject   @end     @pr ...