DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS進階教程
簡單實用的網頁表格特效六例
編輯:CSS進階教程     

以下六個表格特效都不需要圖片,只用 CSS 與少量行內事件即可完成,適合直接複製到自己的專案裡調整。

一、彩色虛線表格

虛 線 表 格

重點是四邊可以各自指定不同的線型與顏色:

<style type="text/css">
<!--
.tab1 {
  border-top-width: thin;
  border-right-width: thin;
  border-bottom-width: thin;
  border-left-width: thin;
  border-top-style: dotted;
  border-right-style: dotted;
  border-bottom-style: dotted;
  border-left-style: dotted;
  border-top-color: #00CC66;
  border-right-color: #0099CC;
  border-bottom-color: #FF0000;
  border-left-color: #6699FF;
}
-->
</style>

<table width="200" border="0" cellpadding="2" cellspacing="2" class="tab1">
<tr>
<td><div align="center">虛</div></td>
<td><div align="center">線</div></td>
</tr>
<tr>
<td><div align="center">表</div></td>
<td><div align="center">格</div></td>
</tr>
</table>

二、滑鼠指向時儲存格變色

onmouseover 是滑鼠放上去的效果,onmouseout 是移開後還原的效果。修改色碼即可換色。

<table width="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td onmouseout="this.style.backgroundColor=''"
    onmouseover="this.style.backgroundColor='#FFcccc'"></td>
</tr>
<tr>
<td onmouseout="this.style.backgroundColor=''"
    onmouseover="this.style.backgroundColor='#FFccaa'"></td>
</tr>
</table>

三、立體表格

立體 表格

靠 bordercolorlight 與 bordercolordark 製造明暗對比,做出凸起或凹陷的視覺:

<table border="1" bordercolorlight="#ffffff" bordercolordark="#ffffff"
  width="200" cellpadding="0" cellspacing="0">
<tr align="center">
<td width="86"
  bordercolorlight="#000000" bordercolordark="#eeeeee" bgcolor="#B7B7B7">立體</td>
<td width="108"
  bordercolorlight="#000000" bordercolordark="#eeeeee" bgcolor="#B7B7B7">表格</td>
</tr>
</table>

四、表格巢狀

做法一:利用 cellspacing 撐出間距。

<table width="200" border="1" cellspacing="4" cellpadding="0">
<tr>
<td></td><td></td><td></td>
</tr>
</table>

做法二:善用對齊方式。把第一個內層表格靠左、第二個靠右、第三個置中,這樣日後調整各表格寬度時,彼此間距會自動保持不變,非常方便。

<table width="200" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
<tr>
<td>
<table width="60" border="1" align="left" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
</table>
<table width="60" border="1" align="right" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
</table>
<table width="80" border="1" align="center" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
</table>
</td>
</tr>
</table>

五、半透明表格

半 透明 表 格

關鍵是 CSS 濾鏡 filter: Alpha(Opacity=20):

<style type="text/css">
<!--
.bg {
  background-color: #66CCFF;
  filter: Alpha(Opacity=20);
}
-->
</style>

<table width="200" border="0" cellpadding="0" cellspacing="0" class="bg">
<tr>
<td><div align="center">半</div></td>
<td><div align="center">透明</div></td>
</tr>
<tr>
<td><div align="center">表</div></td>
<td><div align="center">格</div></td>
</tr>
</table>

提醒:Alpha 濾鏡是 IE 專屬語法。跨瀏覽器請改用 opacity: 0.2;若只想讓背景半透明而文字保持不透明,則改用 rgba() 指定背景色。

六、陰影表格

111  222  333

用到的是 filter: shadow(color=#cccccc, direction=120) 搭配右下方的 padding 留出陰影空間:

<div style="filter:shadow(color=#cccccc,direction=120);width:300;
  padding-right:10;padding-bottom:10">
  <table width="300" border="1" bgcolor="#EAEAEA">
  <tr>
    <td width="93">111</td>
    <td width="91">222</td>
    <td width="94">333</td>
  </tr>
  </table>
</div>

標準做法則是用 box-shadow: 4px 4px 10px #ccc;,一行取代整個濾鏡加 padding 的組合。

附:插入 CSS 樣式的兩種方式

以半透明表格為例。第一種是定義一個類別名稱:

<style type="text/css">
<!--
.bg {
  background-color: #66CCFF;
  filter: Alpha(Opacity=20);
}
-->
</style>

使用時只要掛上 class:

<table width="200" border="0" cellpadding="0" cellspacing="0" class="bg">

第二種是直接在使用到的元素上寫 style="...",把規則放進引號中即可,不必另外定義類別。

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