`
chungle
  • 浏览: 59972 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Top 10 CSS Table Designs

阅读更多

原文:http://www.smashingmagazine.com/2008/08/13/top-10-css-table-designs/

Tables have got to be one of the most difficult objects to style in the Web, thanks to the cryptic markup, the amount of detail we have to take care of, and lack of browser compatibility. A lot of time could be wasted on a single table although it’s just a simple one. This is where this article comes in handy. It will show you ten most easily implemented CSS table designs so you can style your tables in a zap!

Header in Top 10 CSS Table Designs

First things first

We start with a valid xhtml 1.0 strict markup. Here is an example of a valid table markup:

<!-- Table markup-->

<table id="...">

	<!-- Table header -->

		<thead>
			<tr>
				<th scope="col" id="...">...</th>
				...
			</tr>
		</thead>

	<!-- Table footer -->

		<tfoot>
	        <tr>
	              <td>...</td>
	        </tr>
		</tfoot>

	<!-- Table body -->

		<tbody>
			<tr>
				<td>...</td>
				...
			</tr>
			...
		</tbody>

</table>

You can read more about xhtml table markup in HTML Dog’s Table Section. I have tested the tables below in Mozilla Firefox 3, IE 6 and 7, Opera 9.x and Safari. Also note that I apply a light blue color scheme to all of these tables to give the article a consistent look. You can modify the color scheme to match your site — thesource package is provided in the end of the article.

Before we start, let’s review the general rule of thumb for styling of tables:

  1. Tables love space. Set the width of tables carefully, according to the content. If you don’t know the perfect width, simply set the width of the table to 100%. Tables look nicer when they have “overwidth”, and when it comes to tables too much width is definitely better than too little width.
  2. Cells need some padding. Sure, each table cell relates to each other. But it doesn’t mean that we have to pull them too close, right? Define some space between the cells, crammed up table cells are so much harder to read.
  3. Treat tables the way you treat content. Tables are read similarly to the way we read text — except it’s harder and it takes more time to read a table. So be careful with the amount of contrast you are giving to your table. Use soft colors — it’s easier for the eyes. Don’t treat your table like it’s a graphical decoration. Make sure that the style you apply to it makes the content more readable, not the other way around.

Now that we are all set up let’s get going, shall we?

1. Horizontal Minimalist

Horizontal tables are tables that are read rather horizontally than vertically. Each entity is represented by a row. You can style these types of tables with minimalist style. Simply set enough padding to the cells (tdand th) and put a 2 pixel border underneath the header.

Employee Salary Bonus Supervisor
Stephen C. Cox $300 $50 Bob
Josephin Tan $150 - Annie
Joyce Ming $200 $35 Andy
James A. Pentel $175 $25 Annie

Because horizontal tables are supposed to be scanned horizontally, clearing the border of the table increases the efficiency of the table. The lack of border, however, makes this table design hard to read if it has too many rows. To counter it we simply add 1 pixel border underneath all td elements:

Employee Salary Bonus Supervisor
Stephen C. Cox $300 $50 Bob
Josephin Tan $150 - Annie
Joyce Ming $200 $35 Andy
James A. Pentel $175 $25 Annie

The tr:hover rules are very useful to aid people reading a minimally designed tables. When the mouse cursor hovers over a cell, the rest of the cells in the same row highlights immediately, making it easier to track things if your tables have multiple columns.

Important!
Carefully finetune the typography and the padding between the cells
Pros
Very easy to style, good for simple tables
Cons
tr:hover rules don’t work in IE 6, table can be confusing if it has too many columns
Play with
Color scheme, typography, tr:hover effects

2. Vertical Minimalist

Although rarely used, vertically oriented tables are useful for categorizing or comparing descriptions of objects, with each entity represented by a column. We can style it in minimalistic style by adding whitespace separators between columns.

Comedy Adventure Action Children
Scary Movie Indiana Jones The Punisher Wall-E
Epic Movie Star Wars Bad Boys Madagascar
Spartan LOTR Die Hard Finding Nemo
Dr. Dolittle The Mummy 300 A Bug’s Life

Add large border-left and border-right with the same color as background. You can use transparent borders if you want, but IE 6 screws it all up. Since this table is supposed to be read from top to bottom (vertically), adding tr:hover does not help and instead makes it harder to read the data. There is perhaps a Javascript-based solution which enables you to highlight the whole column when a mouseover event occurs, but that’s beyond the scope of this article.

Important!
Carefully finetune the typography and the padding between the cells, do not add tr:hover effect
Pros
Easy to style, good for simple tables
Cons
Can not be used if background is not a solid block of color, suitable only for some tables
Play With
Color scheme and typography

3. Box

The most dependable of all styles, the box style works for all kinds of tables. Pick a good color scheme and then distribute background-color to all the cells. Don’t forget to accentuate the differences of each cell by defining border as a separator. An example of a box style table is the following table:

Employee Salary Bonus Supervisor
Stephen C. Cox $300 $50 Bob
Josephin Tan $150 - Annie
Joyce Ming $200 $35 Andy
James A. Pentel $175 $25 Annie
Comedy Adventure Action Children
Scary Movie Indiana Jones The Punisher Wall-E
Epic Movie Star Wars Bad Boys Madagascar
Spartan LOTR Die Hard Finding Nemo
Dr. Dolittle The Mummy 300 A Bug’s Life

This style is nowadays probably the most used style. The tricky part is actually trying to find the color scheme that matches with your site. If your site is heavy on graphics, it will be pretty hard to use this style.

Important!
Choose a color scheme that matches with your site
Pros
Easy to style, flexible for large or small tables
Cons
Choosing the perfect color scheme could be tricky
Play with
Colors and borders, use dashed or dotted to achieve cute effects, typography, icons

4. Horizontal Zebra

Zebra-tables are pretty attractive and usable. The alternating background color can serve as a visual cue for people when scanning the table. To style a table as zebra, simply put a class="odd" to every odd ordered tr tag and define a style for it (e.g. using if ($count % 2) then even class else odd class in PHP).

	...

		<tr class="odd">
		   <td>...</td>
		   ...
		</tr>

		<tr>
		   <td>...</td>
		   ...
		</tr>

	...
Employee Salary Bonus Supervisor
Stephen C. Cox $300 $50 Bob
Josephin Tan $150 - Annie
Joyce Ming $200 $35 Andy
James A. Pentel $175 $25 Annie
Important!
Do not put too much contrast on the zebra colors, you can blind your users
Pros
The zebra pattern can help people to scan the table
Cons
Adding class="odd" manually can be very tedious for large tables, many content management systems do not provide even/odd features on a table loop, hence picking the color scheme may be tricky
Play With
Contrasting color, borders, typography, icons

5. Vertical Zebra Style

Vertical zebra is easier to style than the horizontal one, as we can make use of colgroup and col elements to distribute column classes. However, the markup becomes a little bit heavier:

<table>

		<!-- Colgroup -->
	   <colgroup>
	      <col class="vzebra-odd">
	      <col class="vzebra-even">
	      <col class="vzebra-odd">
	      <col class="vzebra-even">
	   </colgroup>

		<!-- Table header -->
	   <thead>
	      <tr>
	         <th scope="col" id="vzebra-comedy">Employee</th>
	         ...
	      </tr>
	   </thead>

	   ...
</table>

The colgroup element actually applies a style or class to the table, columnwise. Instead of tediously applying class for the first td or th element, we can use a more convenient colgroup-tag. For more information about colgroup visit this page.

Comedy Adventure Action Children
Scary Movie Indiana Jones The Punisher Wall-E
Epic Movie Star Wars Bad Boys Madagascar
Spartan LOTR Die Hard Finding Nemo
Dr. Dolittle The Mummy 300 A Bug’s Life

Although perhaps more suitable for vertically-oriented table, this zebra-style can also be used for any other kind of tables.

Important!
Do not put too much contrast on the zebra colors, you can blind your viewer
Pros
Suitable for all types of tables
Cons
Choosing the color scheme could be tricky, need to add colgroup elements
Play With
Contrasting color, borders, colgroup and col, icons and typography

6. One Column Emphasis

In some tables, some particular column may have a higher weight than the other columns. If that’s the case, you can use colgroup and col to make that particular column stand out. In the example below, the first column serves as the starting point to read, so it is emphasized, just like we emphasize the first letter of the paragraph as drop caps:

Company Q1 Q2 Q3 Q4
Microsoft 20.3 30.5 23.5 40.3
Google 50.2 40.63 45.23 39.3
Apple 25.4 30.2 33.3 36.7
IBM 20.4 15.6 22.3 29.3

You can also use one-column-emphasis-technique to highlight something important, say the column containing totals of an accounting table, or in a comparison table — for computer specification perhaps, the winning entity (column).

Important!
Be careful, don’t overdo the emphasis or the column will jump out, distracting the effort to read the rest of the columns.
Pros
Very effective when used in certain kind of tables
Cons
The necessary tr:hover effect does not work in IE, suitable for certain types of tables only
Play with
Color scheme, typography, icons and tr:hover effects

7. Newspaper

To achieve the so-called newspaper effect, apply border to table element and play with the cells inside. A quick, minimalistic newspaper style can look like this:

Company Q1 Q2 Q3 Q4
Microsoft 20.3 30.5 23.5 40.3
Google 50.2 40.63 45.23 39.3
Apple 25.4 30.2 33.3 36.7
IBM 20.4 15.6 22.3 29.3

Simply play with color scheme, borders, padding, backgrounds, and tr:hover effects of the cells (td andth). Other alternatives are presented below:

Company Q1 Q2 Q3 Q4
The above data were fictional and made up, please do not sue me
Microsoft 20.3 30.5 23.5 40.3
Google 50.2 40.63 45.23 39.3
Apple 25.4 30.2 33.3 36.7
IBM 20.4 15.6 22.3 29.3
FAVORITE GREAT NICE BAD
Passion of the Christ Bourne Ultimatum Shoot ‘Em Up Ali
The Big Fish The Mummy Apocalypto Monster
Shawshank Redemption Cold Mountain Indiana Jones Dead or Alive
Greatest Story Ever Told I Am Legend Star Wars Saw 3
Important!
Be careful with border-collapse, do not lose the signature border around the table!
Pros
Gives a royal, authorative aura to a table
<dt sty
分享到:
评论

相关推荐

    Table常用的几种CSS样式

    参考链接提供的资源《Top 10 CSS Table Designs》提供了更多灵感和实例,可以帮助开发者进一步提升表格的美观性和功能性。在实际工作中,应不断探索和学习新的CSS技术,以适应不断变化的网页设计趋势。

    好看的css table列表样式

    好看的css table列表样式

    css table 表格标签

    在网页设计中,CSS(Cascading Style Sheets)是一种用于控制网页元素呈现样式的语言,而HTML中的`&lt;table&gt;`标签则是用来创建表格布局的重要元素。`&lt;table&gt;`标签允许我们构建复杂的表格结构,包括行(`&lt;tr&gt;`)、列(`...

    纯css实现table滚动条(纯css实现div滚动条)

    纯css实现table滚动条(纯css实现div滚动条),主要是通过设定高度/宽度及overflow:auto;实现.

    纯css table 样式布局制作人口统计table表格样式代码

    在网页设计中,CSS(Cascading Style Sheets)是一种用于控制网页元素呈现样式的语言,而表格(Table)则是组织数据的重要方式。本教程将详细讲解如何使用纯CSS来制作一个人口统计表格的样式布局。 首先,我们需要...

    好看的css table样式

    在这个主题中,我们聚焦于“好看的css table样式”,这在创建报表、数据展示以及各种信息汇总的网页中尤其重要。 一个美观的CSS表格不仅需要清晰易读,还要具有良好的可读性和吸引力。下面我们将深入探讨如何使用...

    HTML Table 漂亮的CSS

    在网页设计中,HTML表格(Table)是一种常用的数据展示方式,而通过应用合适的CSS(Cascading Style Sheets)样式,我们可以让这些表格看起来更加美观、专业。本资源包"HTML Table 漂亮的CSS"提供了多种独立的CSS...

    CSS样式Table[3] - practical-css3-tables-with-rounded-corners-demo

    本主题“CSS样式Table[3] - practical-css3-tables-with-rounded-corners-demo”着重讨论如何使用CSS3来创建具有圆角的表格,提升网页的视觉效果。我们将深入探讨CSS3中的相关属性和技术,以及如何通过实例代码...

    Table转div+css工具

    在网页设计领域,布局方式的发展经历了从表格(Table)到层(Div)+CSS的转变。"Table转div+css工具"就是专为此目的而设计的一款实用软件,它能够帮助开发者将原有的基于表格的HTML代码转换成使用Div和CSS进行布局的...

    利用CSS控制表格table的交替颜色

    本文将详细介绍如何通过CSS控制表格`&lt;table&gt;`的交替颜色,并提供具体的代码示例。 ### 一、基本原理 在HTML中,`&lt;table&gt;`元素用于创建表格,而`&lt;tr&gt;`代表表格的一行,`&lt;td&gt;`则表示表格中的一个单元格。CSS提供了...

    CSS Table

    在这个主题"CSS Table"中,我们将探讨如何使用CSS来创建和美化表格,以及如何制作出交互式的菜单。 CSS不仅可以改变文本的字体、颜色和大小,还能控制布局,包括表格的样式。 一、CSS与表格 在HTML中,`&lt;table&gt;`...

    table表格,让thead固定,tbody有滚动条,关键是都对齐的纯css写法

    table表格,让thead固定,tbody有滚动条,关键是都对齐的纯css写法。table表格,让thead固定,tbody有滚动条,关键是都对齐的纯css写法。table表格,让thead固定,tbody有滚动条,关键是都对齐的纯css写法。table...

    CSS样式TABLE的一些特效

    在这个主题“CSS样式TABLE的一些特效”中,我们将深入探讨如何利用CSS来增强表格的视觉吸引力和交互性。 1. **表格边框与填充** - `border-collapse`: 这个属性用于设置表格单元格之间的边框合并方式。默认情况下...

    漂亮的table样式(内附css)

    "漂亮的table样式(内附css)"这个主题就是围绕如何使用CSS为HTML表格添加吸引力,使其更加美观和专业。 首先,我们需要了解HTML表格的基本结构,它由`&lt;table&gt;`元素开始,然后包含`&lt;tr&gt;`(行)元素,每个`&lt;tr&gt;`中...

    非常漂亮的css+table+js BS模板

    标题 "非常漂亮的css+table+js BS模板" 暗示了这是一个基于Bootstrap框架的网页设计模板,结合了CSS、HTML表格(Table)以及JavaScript技术,以创建美观且功能丰富的用户界面。Bootstrap是一个流行的前端开发框架,...

    css table width表格宽度样式设置定义.docx

    &lt;table class="divcss5"&gt;...&lt;/table&gt; ``` 这样,只有添加了这个类的 table 标签的宽度才为 300px,而其他的 table 标签则不受影响。 三、总结 定义宽度属性是一个基本的 Web 开发技术,无论是 div、span 还是 ...

    css背景色和table样式,一些参考

    在CSS(层叠样式表)中,背景色是设置元素背景颜色的一种基本属性,它可以用于任何HTML或XML文档,包括HTML表格(table)。表格样式在网页设计中扮演着重要角色,尤其是在展示数据时。本篇将详细介绍CSS背景色的用法...

    CSS 美化Table,可以多选Table的行和列

    在网页设计中,表格(Table)是展示数据的重要方式,而CSS(Cascading Style Sheets)则赋予了我们对表格进行美化的能力。本教程将深入探讨如何使用CSS来提升表格的视觉效果,并实现多选表格的行和列功能,这对于...

    table 圆角 html5 css3

    在HTML5和CSS3的世界里,为表格(table)添加圆角效果是一项常见的美化任务,可以使得网页设计更具现代感和优雅。本文将深入探讨如何使用HTML5和CSS3实现表格的圆角效果,以及相关的知识点。 首先,HTML5虽然在语义...

    用CSS为表格添加阴影效果.rar

    top: 0; left: 0; width: 100%; height: 100%; box-shadow: 2px 2px 5px 0 rgba(0, 0, 0, 0.3); z-index: -1; } ``` 这样,阴影被置于表格之上,不会受到表格边框的影响。 在压缩包中的`index.htm`文件中,...

Global site tag (gtag.js) - Google Analytics