诺亚方舟

沉淀

四个好看的CSS样式表格(转)

1. 单像素边框CSS表格

这是一个很常用的表格样式。

源代码:

 

1
<!-- CSS goes in the document HEAD or added to your external stylesheet -->

Info Header 1 Info Header 2 Info Header 3
Text 1A Text 1B Text 1C Text 2A Text 2B Text 2C

2. 带背景图的CSS样式表格

和上面差不多,不过每个格子里多了背景图。

 

cell-blue.jpg

cell-grey.jpg

 

1. 下载上面两张图,命名为cell-blue.jpg和cell-grey.jpg

2. 拷贝下面的代码到你想要的地方,记得修改图片url

1
<!-- CSS goes in the document HEAD or added to your external stylesheet -->

Info Header 1 Info Header 2 Info Header 3
Text 1A Text 1B Text 1C Text 2A Text 2B Text 2C

3. 自动换整行颜色的CSS样式表格(需要用到JS)

这个CSS样式表格自动切换每一行的颜色,在我们需要频繁更新一个大表格的时候很有用。

 

代码:

 

1
2
3
4
5
6
7
8
9
<!-- Javascript goes in the document HEAD --><script type="text/javascript">// <![CDATA[
function altRows(id){
	if(document.getElementsByTagName){  
 
		var table = document.getElementById(id);  
		var rows = table.getElementsByTagName("tr"); 
 
		for(i = 0; i < rows.length; i++){           			if(i % 2 == 0){ 				rows[i].className = "evenrowcolor"; 			}else{ 				rows[i].className = "oddrowcolor"; 			}       		} 	} } window.onload=function(){ 	altRows('alternatecolor'); }
// ]]></script><!-- CSS goes in the document HEAD or added to your external stylesheet -->

Info Header 1 Info Header 2 Info Header 3
Text 1A Text 1B Text 1C Text 2A Text 2B Text 2C Text 3A Text 3B Text 3C Text 4A Text 4B Text 4C Text 5A Text 5B Text 5C

4. 鼠标悬停高亮的CSS样式表格 (需要JS)

纯CSS显示表格高亮在IE中显示有问题,所以这边使用了JS来做高亮(由于csdn博客限制了js的使用,我会在近期将博客迁移放到自己的web主机上)。

 

有一点要小心的是,不要定义格子的背景色。

1
<!-- CSS goes in the document HEAD or added to your external stylesheet -->

Info Header 1 Info Header 2 Info Header 3
Item 1A Item 1B Item 1C Item 2A Item 2B Item 2C Item 3A Item 3B Item 3C Item 4A Item 4B Item 4C Item 5A Item 5B Item 5C

文章转自HTML Tables with CSS Styles

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>