漂亮的表格样式–>使用CSS样式表控制表格样式
依照WEB2.0风格,设计了几个表格样式,希望大家喜欢。WEB2.0提倡使用div开布局,但不是要完全放弃使用表格,表格在数据展现方面还是不错的选择。现在介绍使用CSS样式表来控制、美化表格的方法。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script type="text/javascript" src="jquery-1.3.1.js"></script> <title>精美的表格样式</title> <style type="text/css"> <!-- body,table{ font-size:12px; } table{ table-layout:fixed; empty-cells:show; border-collapse: collapse; margin:0 auto; } td{ height:20px; } h1,h2,h3{ font-size:12px; margin:0; padding:0; } .title { background: #FFF; border: 1px solid #9DB3C5; padding: 1px; width:90%;margin:20px auto; } .title h1 { line-height: 31px; text-align:center; background: #2F589C url(th_bg2.gif); background-repeat: repeat-x; background-position: 0 0; color: #FFF; } .title th, .title td { border: 1px solid #CAD9EA; padding: 5px; } //样式一 table.tab_css_1{ border:1px solid #cad9ea; color:#666; } table.tab_css_1 th { background-image: url(th_bg1.gif); background-repeat::repeat-x; height:30px; } table.tab_css_1 td,table.tab_css_1 th{ border:1px solid #cad9ea; padding:0 1em 0; } table.tab_css_1 tr.tr_css{ background-color:#f5fafe; } //样式二 table.tab_css_2{ border:1px solid #9db3c5; color:#666; } table.tab_css_2 th { background-image: url(th_bg2.gif); background-repeat::repeat-x; height:30px; color:#fff; } table.tab_css_2 td{ border:1px dotted #cad9ea; padding:0 2px 0; } table.tab_css_2 th{ border:1px solid #a7d1fd; padding:0 2px 0; } table.tab_css_2 tr.tr_css{ background-color:#e8f3fd; } //样式三 table.tab_css_3{ border:1px solid #fc58a6; color:#720337; } table.tab_css_3 th { background-image: url(th_bg3.gif); background-repeat::repeat-x; height:30px; color:#35031b; } table.tab_css_3 td{ border:1px dashed #feb8d9; padding:0 1.5em 0; } table.tab_css_3 th{ border:1px solid #b9f9dc; padding:0 2px 0; } table.tab_css_3 tr.tr_css{ background-color:#fbd8e8; } .hover{ background-color: #53AB38; color: #fff; } --> </style> <script type="text/javascript"> function ApplyStyle(s){ document.getElementById("mytab").className=s.innerText; } $(function(){ addHover('mytab'); }); /** * 在鼠标悬停时突出显示行--jQuery处理表格 * * @tab table id */ function addHover(tab){ $('#'+tab+' tr').hover( function(){ $(this).find('td').addClass('hover'); }, function(){ $(this).find('td').removeClass('hover'); } ); } </script> </head> <body> <div class="title"> <h1>大家好,CSS与表格的结合示例</h1> <table><tr><td> 点击链接切换样式:<a href="javascript:;" onclick="ApplyStyle(this)">tab_css_1</a> <a href="javascript:;" onclick="ApplyStyle(this)">tab_css_2</a> <a href="javascript:;" onclick="ApplyStyle(this)">tab_css_3</a> </td></tr></table> </div> <table width="90%" id="mytab" border="1" class="tab_css_1"> <thead> <th width="10%">网名</th> <th width="30%">博客</th> <th width="20%">电邮</th> <th width="10%">QQ</th> </thead> <tr class="tr_css"> <td>Ruthless</td> <td>http://www.tieguanyin168.com/</td> <td>416501600@qq.com</td> <td>416501600</td> </tr> <tr> <td>Ruthless</td> <td>http://www.tieguanyin168.com/</td> <td>416501600@qq.com</td> <td>416501600</td> </tr> <tr class="tr_css"> <td>Ruthless</td> <td>http://www.tieguanyin168.com/</td> <td>416501600@qq.com</td> <td>416501600</td> </tr> <tr> <td>Ruthless</td> <td>http://www.tieguanyin168.com/</td> <td>416501600@qq.com</td> <td>416501600</td> </tr> <tr class="tr_css"> <td>Ruthless</td> <td>http://www.tieguanyin168.com/</td> <td>416501600@qq.com</td> <td>416501600</td> </tr> <tr> <td>Ruthless</td> <td>http://www.tieguanyin168.com/</td> <td>416501600@qq.com</td> <td>416501600</td> </tr> <tr class="tr_css"> <td>Ruthless</td> <td>http://www.tieguanyin168.com/</td> <td>416501600@qq.com</td> <td>416501600</td> </tr> <tr> <td>Ruthless</td> <td>http://www.tieguanyin168.com/</td> <td>416501600@qq.com</td> <td>416501600</td> </tr> </table> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)