[转]Responsive Tables Demo

本文转自: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. }
时间: 2024-08-24 03:56:08

[转]Responsive Tables Demo的相关文章

DataTable到Access

conn.Open();                                      OleDbDataAdapter Bada = new OleDbDataAdapter("select * from " + cmdText, conn);//建立一个DataAdapter对象                    OleDbCommandBuilder cb = new OleDbCommandBuilder(Bada);//这里的CommandBuilder对象一

响应式布局(Responsive layout,RL)的简单Demo

★背景: 响应式布局是Ethan Marcotte在2010年5月份提出的一个概念,简而言之,就是一个网站能够兼容多个终端——而不是为每个终端做一个特定的版本.这个概念是为解决移动互联网浏览而诞生的. 响应式布局可以为不同终端的用户提供更加舒适的界面和更好的用户体验,而且随着目前大屏幕移动设备的普及,用“大势所趋”来形容也不为过.随着越来越多的设计师采用这个技术,我们不仅看到很多的创新,还看到了一些成形的模式. ★利弊分析 凡事有利必有弊.响应式布局的优缺点也是有必要了解的. 优点:面对不同分辨

Responsive design for tables

运用本文的CSS 可以是table变成响应式设计 CSS代码如下: /* ----------------------------------------- Table - Clickable row fakery ----------------------------------------- */ /* Generic table style - app overwrites */ table { *border-collapse: collapse; /* IE7 and lower *

Understanding apps: mobile, native or responsive

Background Maybe you have decided to get an app built. You will not build it yourself (obviously!) so you have done your homework properly, went out and got a few quotes (that’s more than 2, please) to establish the cost of getting this built. The on

mybaits入门demo映射文件详解(三)

第二篇文章:  mybaits入门demo配置文件详解(二) Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同功能的 JDBC 代码进行对比,你会立即发现省掉了将近 95% 的代码.MyBatis 就是针对 SQL 构建的,并且比普通的方法做的更好. SQL 映射文件有很少的几个顶级元素(按照它们应该被定义的顺序): cache – 给定命名空间的缓存配置. cache-ref –

jQuery Mboile Demo By:凉游浅笔深画眉

Effect:         jQuery Mobile is a HTML5-based user interface system designed to make responsive web sites and apps that are accessible on all smartphone, tablet and desktop devices.jQuery Mobile framework takes the "write less, do more" mantra

【转】WCF入门教程六[一个简单的Demo]

一.前言 前面的几个章节介绍了很多理论基础,如:什么是WCF.WCF中的A.B.C.WCF的传输模式.本文从零开始和大家一起写一个小的WCF应用程序Demo. 大多框架的学习都是从增.删.改.查开始来学习的,我们学习WCF也是一样的.从简单来看(不包括安全.优化等相关问题),WCF的增删改查和WebForm相差无几.WCF只是把具体"实现"写在"Service端",而"调用"放在了"Client端".觉得有帮助别忘了点个赞哈,

无废话WCF入门教程六[一个简单的Demo]

wcf技术交流,同学习,同进步. 群号:89718412 一.前言 前面的几个章节介绍了很多理论基础,如:什么是WCF.WCF中的A.B.C.WCF的传输模式.本文从零开始和大家一起写一个小的WCF应用程序Demo. 大多框架的学习都是从增.删.改.查开始来学习的,我们学习WCF也是一样的.从简单来看(不包括安全.优化等相关问题),WCF的增删改查和WebForm相差无几.WCF只是把具体“实现”写在“Service端”,而“调用”放在了“Client端”.觉得有帮助别忘了点个赞哈,谢谢哦~ 二

WCF系列之一个简单的Demo

一.前言     前面的几个章节介绍了很多理论基础,如:什么是WCF.WCF中的A.B.C.WCF的传输模式.本文从零开始和大家一起写一个小的WCF应用程序Demo.     大多框架的学习都是从增.删.改.查开始来学习的,我们学习WCF也是一样的.从简单来看(不包括安全.优化等相关问题),WCF的增删改查和WebForm相差无几.WCF只是把具体"实现"写在"Service端",而"调用"放在了"Client端".觉得有帮助