DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> WEB網站前端 >> WEB前端代碼 >> 幾種實用table樣式
幾種實用table樣式
編輯:WEB前端代碼     
查看效果:http:///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/phtml/">Text 1A</a></td>
<td><a href="http:///a/bjad/b1lipq9t.htm">Text 1B</a></td>
<td><a href="http://">Text 1C</a></td>
</tr>
<tr>
<td><a href="http:///a/bjac/u1i5j3g9.htm">Text 2A</a></td>
<td><a href="http:///ziliao/googlejavascriptstyle.htm">Text 2B</a></td>
<td><a href="http://h./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/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/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://">Text 1A</a></td>
<td><a href="http://">Text 1B</a></td>
<td><a href="http://">Text 1C</a></td>
</tr>
<tr>
<td><a href="http:///a/bjae/t5mo1rqe.htm">Text 2A</a></td>
<td><a href="http:///a/bjad/aqqsi7eb.htm">Text 2B</a></td>
<td><a href="http:///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://">Text 1A</a></td>
<td><a href="http://">Text 1B</a></td>
<td><a href="http:///a/bjae/9dbvc2eg.htm">Text 1C</a></td>
</tr>
<tr>
<td><a href="http://">Text 2A</a></td>
<td><a href="http://">Text 2B</a></td>
<td><a href="http://">Text 2C</a></td>
</tr>
<tr>
<td><a href="http://">Text 3A</a></td>
<td><a href="http://">Text 3B</a></td>
<td><a href="http://">Text 3C</a></td>
</tr>
<tr>
<td><a href="http:///a/bjac/yk6l1vko.htm">Text 4A</a></td>
<td><a href="http:///a/bjae/h1o76nuh.htm">Text 4B</a></td>
<td><a href="http:///a/bjad/8e9jd0u5.htm">Text 4C</a></td>
</tr>
<tr>
<td><a href="http:///a/bjad/loatox9d.htm">Text 5A</a></td>
<td><a href="http:///a/bjad/nvy3vslt.htm">Text 5B</a></td>
<td><a href="http:///a/bjac/qwcsgskp.htm">Text 5C</a></td>
</tr>
</table>

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

<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://">Item 1A</a></td>
<td><a href="http://">Item 1B</a></td>
<td><a href="http://">Item 1C</a></td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://">Item 2A</a></td>
<td><a href="http://">Item 2B</a></td>
<td><a href="http://">Item 2C</a></td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://">Item 3A</a></td>
<td><a href="http://">Item 3B</a></td>
<td><a href="http://">Item 3C</a></td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://">Item 4A</a></td>
<td><a href="http://">Item 4B</a></td>
<td><a href="http://">Item 4C</a></td>
</tr>
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td><a href="http://">Item 5A</a></td>
<td><a href="http://">Item 5B</a></td>
<td><a href="http://">Item 5C</a></td>
</tr>
</table>



</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved