您的位置:首页 - web前端
几种实用table样式
查看效果:http://keleyi.com/keleyi/phtml/divcss/23.htm

1. 单像素边框CSS表格

这是一个非经常常使用的表格样式。

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

和上面差点儿相同,只是每一个格子里多了背景图。


3. 自己主动换整行颜色的CSS样式表格(须要用到JS)
这个CSS样式表格自己主动切换每一行的颜色,在我们须要频繁更新一个大表格的时候非常实用。


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

纯CSS显示表格高亮在IE中显示有问题,所以这边使用了JS来做高亮(因为csdn博客限制了js的使用,我会在最近将博客迁移放到自己的web主机上)。
有一点要小心的是,不要定义格子的背景色。

html代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>几种实用table样式-柯乐义</title>
<style> a {
color:black;text-decoration:none }
</style>
</head>
<body>
<h2>单像素边框CSS表格</h2>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.keleyigridtable {
font-family: verdana,arial,sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}

table.keleyigridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}

table.keleyigridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>

<!-- Table goes in the document BODY -->
<table class="keleyigridtable">
<tr>
<th>Info Header 1</th>
<th>Info Header 2</th>
<th>Info Header 3</th>
</tr>
<tr>
<td><a href="http://keleyi.com/keleyi/phtml/">Text 1A</a></td>
<td><a href="http://keleyi.com/a/bjad/b1lipq9t.htm">Text 1B</a></td>
<td><a href="http://keleyi.com">Text 1C</a></td>
</tr>
<tr>
<td><a href="http://keleyi.com/a/bjac/u1i5j3g9.htm">Text 2A</a></td>
<td><a href="http://keleyi.com/ziliao/googlejavascriptstyle.htm">Text 2B</a></td>
<td><a href="http://h.keleyi.com/guestbook/">Text 2C</a></td>
</tr>
</table>

<h2>带背景图的表格</h2>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.imagetable {
font-family: verdana,arial,sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}

table.imagetable th {
background: #b5cfd2 url('http://keleyi.com/keleyi/phtml/divcss/23/cell-blue.jpg');
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #999999;
}

table.imagetable td {
background: #dcddc0 url('http://keleyi.com/keleyi/phtml/divcss/23/cell-grey.jpg');
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #999999;
}
</style>
<!-- Table goes in the document BODY -->
<table class="imagetable">
<tr>
<th>Info Header 1</th>
<th>Info Header 2</th>
<th>Info Header 3</th>
</tr>
<tr>
<td><a href="http://keleyi.com">Text 1A</a></td>
<td><a href="http://keleyi.com">Text 1B</a></td>
<td><a href="http://keleyi.com">Text 1C</a></td>
</tr>
<tr>
<td><a href="http://keleyi.com/a/bjae/t5mo1rqe.htm">Text 2A</a></td>
<td><a href="http://keleyi.com/a/bjad/aqqsi7eb.htm">Text 2B</a></td>
<td><a href="http://keleyi.com/a/bjad/mib7yyfs.htm">Text 2C</a></td>
</tr>
</table>

<h2>隔行换色表格</h2>

<!-- Javascript goes in the document HEAD -->
<script type="text/javascript">
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('kele'+'yicolor');
}
</script>


<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.altrowstable {
font-family: verdana,arial,sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #a9c6c9;
border-collapse: collapse;
}

table.altrowstable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}

table.altrowstable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}

.oddrowcolor {
background-color: #d4e3e5;
}

.evenrowcolor {
background-color: #c3dde0;
}
</style>


<!-- Table goes in the document BODY -->
<table class="altrowstable" id="keleyicolor">
<tr>
<th>Info Header 1</th>
<th>Info Header 2</th>
<th>Info Header 3</th>
</tr>
<tr>
<td><a href="http://keleyi.com">Text 1A</a></td>
<td><a href="http://keleyi.com">Text 1B</a></td>
<td><a href="http://keleyi.com/a/bjae/9dbvc2eg.htm">Text 1C</a></td>
</tr>
<tr>
<td><a href="http://keleyi.com">Text 2A</a></td>
<td><a href="http://keleyi.com">Text 2B</a></td>
<td><a href="http://keleyi.com">Text 2C</a></td>
</tr>
<tr>
<td><a href="http://keleyi.com">Text 3A</a></td>
<td><a href="http://keleyi.com">Text 3B</a></td>
<td><a href="http://keleyi.com">Text 3C</a></td>
</tr>
<tr>
<td><a href="http://keleyi.com/a/bjac/yk6l1vko.htm">Text 4A</a></td>
<td><a href="http://keleyi.com/a/bjae/h1o76nuh.htm">Text 4B</a></td>
<td><a href="http://keleyi.com/a/bjad/8e9jd0u5.htm">Text 4C</a></td>
</tr>
<tr>
<td><a href="http://keleyi.com/a/bjad/loatox9d.htm">Text 5A</a></td>
<td><a href="http://keleyi.com/a/bjad/nvy3vslt.htm">Text 5B</a></td>
<td><a href="http://keleyi.com/a/bjac/qwcsgskp.htm">Text 5C</a></td>
</tr>
</table>

<!-- The table code can be found here: http://keleyi.com -->

<h2>鼠标悬停行高亮表格</h2>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
table.hovertable {
font-family: verdana,arial,sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}

table.hovertable th {
background-color: #c3dde0;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}

table.hovertable tr {
background-color: #d4e3e5;
}

table.hovertable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #a9c6c9;
}
</style>

<!-- Table goes in the document BODY -->
<table class="hovertable">
<tr>
<th>Info Header 1</th>
<th>Info Header 2</th>
<th>Info Header 3</th>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://keleyi.com">Item 1A</a></td>
<td><a href="http://keleyi.com">Item 1B</a></td>
<td><a href="http://keleyi.com">Item 1C</a></td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://keleyi.com">Item 2A</a></td>
<td><a href="http://keleyi.com">Item 2B</a></td>
<td><a href="http://keleyi.com">Item 2C</a></td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://keleyi.com">Item 3A</a></td>
<td><a href="http://keleyi.com">Item 3B</a></td>
<td><a href="http://keleyi.com">Item 3C</a></td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://keleyi.com">Item 4A</a></td>
<td><a href="http://keleyi.com">Item 4B</a></td>
<td><a href="http://keleyi.com">Item 4C</a></td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://keleyi.com">Item 5A</a></td>
<td><a href="http://keleyi.com">Item 5B</a></td>
<td><a href="http://keleyi.com">Item 5C</a></td>
</tr>
</table>



</body>
</html>
本站导航
相关文章
柯乐义 Copyright© keleyi.com