`
endual
  • 浏览: 3566494 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

html 表格设计

 
阅读更多

Top 10 CSS Table Designs

By R. Christie

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!

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 thetable 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 (td and 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 amouseover event occurs, but that’s beyond the scope of this article.

Important!
Carefully finetune the typography and the padding between the cells, do not addtr: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 ofcolgroup 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:hovereffects of the cells (td and th). 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
Cons
Unsuitable for large tables (it loses it’s charm on large tables)
Play With
Typography, color scheme, background, border, padding, and tr:hover effects

8. Rounded Corner

Rounded corners are slick and modern, and it’s easy to apply it to a table, although you need to fire up Photoshop for this. Create images for all four corners of your table. Theoretically, we can make use of the nesting tr and td-elements to place the left and right corners of the table without adding additional markup. Unfortunately, IE 6 goes berserk and the table appears ugly, so the most stable way to do this is to put ID or class to all four corner cells of the table. Please consider the example 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
Pros
Great if you want untraditional table, probably the only viable option you have if your website uses rounded corners heavily
Cons
Takes longer to style, requires images
Play With
Color scheme, corner variations, typography, tr:hover effects, icons

9. Table Background

If you are looking for a quick and unique way to style your table, simply pick an attractive image or photo related to the subject of your table and set it to be thebackground-image of the table. You can add 50% grey png-image as background-image of the cells to improve readability, and that means that you need a CSS-hack to make it work in IE 6:

* html table tbody td
{

		  /* IE CSS Filter Hack goes here*/

}

The table would look like this:

Employee Division Suggestions
IE 6 users won’t see the transparent background if the hack is not applied
Stephen C. Cox Marketing Make discount offers
Josephin Tan Advertising Give bonuses
Joyce Ming Marketing New designs
James A. Pentel Marketing Better Packaging
Important!
Make sure the image is relevant to the table’s contents
Pros
Very easy to style, delivers unique look, if used correctly the image can serve as a symbol that gives outstanding impression on the viewer
Cons
Needs hack to get the background work in IE 6, needs images
Play With
Background images, transparent PNGs, typography, colors, icons

10. Cell Background

You can apply background-image to the cells and achieve a consistent look. Say you have at least half an hour to spare and you want something that’s not too bland. Start your Photoshop and make 1 pixel width gradients, and set them asbackground-image of all cells. You’ll end up with a gradient style table:

Employee Division Suggestions Rating
Give background color to the table cells to achieve seamless transition
Stephen C. Cox Marketing Make discount offers 3/10
Josephin Tan Advertising Give bonuses 5/10
Joyce Ming Marketing New designs 8/10
James A. Pentel Marketing Better Packaging 8/10

Similarly, pick a pattern and set it as background-image and you’ll end up with a pattern-styled-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
Nation Capital Language Unique
Japan Tokyo Japanese Karate
South Korea Seoul Korean Ginseng
China Beijing Mandarin Kung-Fu
Indonesia Jakarta Indonesian Batik
Important!
Make sure the text stands out against the background
Pros
Easy to style, not too bland
Cons
Uses images, patterns and gradients might distract reading
Play With
Color scheme, patterns, typography, borders, backgrounds, gradients, icons

Final Words

I know I barely scratched the surface with this article, so grab the source and play around. Feel free to post your favourite table designs, especially if it’s something I missed out. Over to you.

ABOUT THE AUTHOR

R.Christie is studying information systems at college. He viciously juggles activities from college, web design, programming, church, to sport activities. You can say hello to him via e-mail.

EDITOR’S NOTE

This post is one of the finalists of our guest author contest. Over three weeks selected top-10-lists and discussion articles will be published. To rate the articles we’ll analyze their popularity, users activity, quality of backlinks, traffic and further data.

How good is the post “Top 10 Express CSS Table Designs”? 
( polls)

Tags:CSSTables

 

分享到:
评论

相关推荐

    html表格设计

    html表格设计,最基础,最基本的,嘻嘻

    基于HTML的表格设计

    这是一个基于html5的会议管理系统的原型设计,表格设计,,,十分简单的 这是一个基于html5的会议管理系统的原型设计,表格设计,,,十分简单的 这是一个基于html5的会议管理系统的原型设计,表格设计,,,十分简单的

    表格 html 表格 html 表格 html

    尽管随着Web技术的发展,`div`+`css`的布局方式逐渐成为主流,但在处理复杂的数据展示时,HTML表格仍然具有不可替代的作用。掌握了表格的基本语法以及各种高级特性,可以更好地利用表格来优化网站的设计和用户体验。

    21个新奇漂亮的AjaxCSS表格设计

    - **Tablecloth**:由CSSGlobe开发,是一个轻量级的表格插件,简化了HTML表格的样式添加过程。 - **AsktheCSSGuy Table**:展示了如何通过点击元素来突出显示其关联数据,增强了数据之间的联系展示。 - **ACSS ...

    漂亮的表格 HTML表格

    在网页设计中,HTML表格是一种常见的数据展示方式。它们用于组织和排列结构化的信息,如数据报告、统计分析等。本教程将深入探讨如何创建“漂亮的表格”并利用HTML、CSS和JavaScript增强用户体验。 首先,HTML是...

    111111111111111111111111111111

    11

    html5移动端表格设计.docx

    HTML5 移动端表格设计主要关注在适应不同设备尺寸、界面组件的规范以及用户体验方面的优化。在HTML5中,创建响应式表格是至关重要的,因为这能确保内容在各种屏幕大小的移动设备上都能清晰、易读且功能正常。 首先...

    html表格和CSS进行网页设计

    HTML表格和CSS是网页设计中的两个关键元素,它们一起构建了网页内容的结构和样式。HTML(HyperText Markup Language)负责定义网页的结构,而CSS(Cascading Style Sheets)则用于控制页面的布局和外观。 HTML表格...

    html好看的表格

    HTML表格是一种常用的数据展示工具,尤其在网页设计中不可或缺。"好看的html表格"是指通过HTML语言,结合CSS样式,创建出既美观又功能强大的表格。本文将深入探讨如何利用HTML和CSS来创建一个吸引人的表格。 首先,...

    html Table 表头固定的实现

    总的来说,通过上述方法,可以较为简单地实现一个固定表头的HTML表格,这个技术在现代网页设计中非常实用,能够提升用户体验,特别是在需要处理大量表格数据时。当然,固定表头的实现还可能会涉及一些其他因素,比如...

    HTML框架,表格

    HTML表格用于在网页上组织数据,使用`&lt;table&gt;`、`&lt;tr&gt;`(行)、`&lt;td&gt;`(数据单元格)和`&lt;th&gt;`(表头单元格)等标签进行创建。以下是一个简单的表格实例: ```html 员工信息 姓名 职位 薪水 张三 经理 ...

    漂亮的表格css+html

    通过学习和实践这些示例,开发者可以掌握创建高效、优雅的HTML表格和CSS样式的技巧,提升网页设计的水平。 记住,优秀的表格设计不仅关注外观,也要考虑用户体验。清晰的布局、易读的字体、合理的色彩搭配以及对...

    表格自己展开HTML效果

    1. **HTML基础结构**:首先,创建一个基本的HTML表格。每一行应包含一个父级元素(用于鼠标悬停事件)和一个子级元素(用于隐藏的子表内容)。例如: ```html 父级数据1 展开/收起 子级数据1 &lt;!-- 更多...

    html表格的应用(Html网页设计参考手册_总十章_第八章)

    HTML表格的应用是网页设计中的重要环节,它是HTML文档对象模型中用于展示数据的一种结构化方式。通过表格,网页设计者可以对网页内容进行分段和排版,使其更加清晰和有序。本知识点将详细介绍如何在HTML中建立和应用...

    html kechengbiao.zip_html_课程 表格 html_课程表_课程表 html

    在本案例中,"html kechengbiao.zip" 提供的是一份与课程相关的HTML文件,它使用了HTML表格(table)来构建一个课程表。课程表是教育机构管理教学计划的重要工具,它清晰地展示了课程的名称、时间、地点等信息。 ...

    html网页设计大作业

    在网页设计中,CSS(层叠样式表)起着至关重要的作用,它负责控制网页的外观和布局。这里出现了多个CSS文件,如style5.css、style3之最.css、style1.css、style4.css、style.css、style2.css,这表明设计者可能尝试...

    html表格头部固定 相应单元格宽度自适应内容区域单元格

    在网页设计中,HTML表格是一种常见的数据展示方式。然而,当表格内容过多导致需要滚动时,表头通常会被滚动条遮挡,给用户查看和理解数据带来不便。为了解决这个问题,我们可以采用“表格头部固定”技术,确保无论...

    HTML表格代码

    HTML表格代码是网页设计中一个非常重要的组件,它能够帮助设计师和开发者快速创建出美观、实用的表格。在本文中,我们将详细介绍HTML表格代码的各种特性和应用场景。 一、基础表格代码 HTML表格代码的基本结构主要...

    基于html家具装饰网站设计毕业设计.rar(含论文毕设+项目源码+答辩设计+成绩评分表+评定表)

    html网页设计,div+css样式布局, 第一章 前言 2 1.1 INTERNET 的历史和发展 2 1.2 网页概述 2 第二章 开发软件简介 3 2.1 网站设计的基本知识 3 2.2 Dreamweaver 2014 简介 3 2.3 HTML 简介 4 2.4 HTML 技术介绍 4 ...

Global site tag (gtag.js) - Google Analytics