table 样式美化

1.单像素边框CSS表格这是一个很常用的表格样式。源代码:1<!–CSSgoesinthedocumentHEADoraddedtoyourexternalstylesheet–>2<styletype=”text/css”>3table.gridtable{4f…

大家好,又见面了,我是你们的朋友全栈君。

1. 单像素边框CSS表格

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

table 样式美化

 

源代码:

复制代码
 1 <!-- CSS goes in the document HEAD or added to your external stylesheet -->
 2 <style type="text/css">
 3 table.gridtable {
 4     font-family: verdana,arial,sans-serif;
 5     font-size:11px;
 6     color:#333333;
 7     border-width: 1px;
 8     border-color: #666666;
 9     border-collapse: collapse;
10 }
11 table.gridtable th {
12     border-width: 1px;
13     padding: 8px;
14     border-style: solid;
15     border-color: #666666;
16     background-color: #dedede;
17 }
18 table.gridtable td {
19     border-width: 1px;
20     padding: 8px;
21     border-style: solid;
22     border-color: #666666;
23     background-color: #ffffff;
24 }
25 </style>
26 
27 <!-- Table goes in the document BODY -->
28 <table class="gridtable">
29 <tr>
30     <th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
31 </tr>
32 <tr>
33     <td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
34 </tr>
35 <tr>
36     <td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
37 </tr>
38 </table>
复制代码

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

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

 

table 样式美化

table 样式美化cell-blue.jpg

table 样式美化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 -->
 2 <style type="text/css">
 3 table.imagetable {
 4     font-family: verdana,arial,sans-serif;
 5     font-size:11px;
 6     color:#333333;
 7     border-width: 1px;
 8     border-color: #999999;
 9     border-collapse: collapse;
10 }
11 table.imagetable th {
12     background:#b5cfd2 url('cell-blue.jpg');
13     border-width: 1px;
14     padding: 8px;
15     border-style: solid;
16     border-color: #999999;
17 }
18 table.imagetable td {
19     background:#dcddc0 url('cell-grey.jpg');
20     border-width: 1px;
21     padding: 8px;
22     border-style: solid;
23     border-color: #999999;
24 }
25 </style>
26 
27 <!-- Table goes in the document BODY -->
28 <table class="imagetable">
29 <tr>
30     <th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
31 </tr>
32 <tr>
33     <td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
34 </tr>
35 <tr>
36     <td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
37 </tr>
38 </table>
复制代码

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

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

table 样式美化

 

代码:

复制代码
 1 <!-- Javascript goes in the document HEAD -->
 2 <script type="text/javascript">
 3 function altRows(id){
 4     if(document.getElementsByTagName){  
 5         
 6         var table = document.getElementById(id);  
 7         var rows = table.getElementsByTagName("tr"); 
 8          
 9         for(i = 0; i < rows.length; i++){          
10             if(i % 2 == 0){
11                 rows[i].className = "evenrowcolor";
12             }else{
13                 rows[i].className = "oddrowcolor";
14             }      
15         }
16     }
17 }
18 
19 window.οnlοad=function(){
20     altRows('alternatecolor');
21 }
22 </script>
23 
24 
25 <!-- CSS goes in the document HEAD or added to your external stylesheet -->
26 <style type="text/css">
27 table.altrowstable {
28     font-family: verdana,arial,sans-serif;
29     font-size:11px;
30     color:#333333;
31     border-width: 1px;
32     border-color: #a9c6c9;
33     border-collapse: collapse;
34 }
35 table.altrowstable th {
36     border-width: 1px;
37     padding: 8px;
38     border-style: solid;
39     border-color: #a9c6c9;
40 }
41 table.altrowstable td {
42     border-width: 1px;
43     padding: 8px;
44     border-style: solid;
45     border-color: #a9c6c9;
46 }
47 .oddrowcolor{
48     background-color:#d4e3e5;
49 }
50 .evenrowcolor{
51     background-color:#c3dde0;
52 }
53 </style>
54 
55 
56 <!-- Table goes in the document BODY -->
57 <table class="altrowstable" id="alternatecolor">
58 <tr>
59     <th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
60 </tr>
61 <tr>
62     <td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
63 </tr>
64 <tr>
65     <td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
66 </tr>
67 </tr>
68 <tr>
69     <td>Text 3A</td><td>Text 3B</td><td>Text 3C</td>
70 </tr>
71 <tr>
72     <td>Text 4A</td><td>Text 4B</td><td>Text 4C</td>
73 </tr>
74 <tr>
75     <td>Text 5A</td><td>Text 5B</td><td>Text 5C</td>
76 </tr>
77 </table>
78 
79 <!--  The table code can be found here: http://www.textfixer/resources/css-tables.php#css-table03 -->
复制代码

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

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

table 样式美化

 

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

复制代码
 1 <!-- CSS goes in the document HEAD or added to your external stylesheet -->
 2 <style type="text/css">
 3 table.hovertable {
 4     font-family: verdana,arial,sans-serif;
 5     font-size:11px;
 6     color:#333333;
 7     border-width: 1px;
 8     border-color: #999999;
 9     border-collapse: collapse;
10 }
11 table.hovertable th {
12     background-color:#c3dde0;
13     border-width: 1px;
14     padding: 8px;
15     border-style: solid;
16     border-color: #a9c6c9;
17 }
18 table.hovertable tr {
19     background-color:#d4e3e5;
20 }
21 table.hovertable td {
22     border-width: 1px;
23     padding: 8px;
24     border-style: solid;
25     border-color: #a9c6c9;
26 }
27 </style>
28 
29 <!-- Table goes in the document BODY -->
30 <table class="hovertable">
31 <tr>
32     <th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
33 </tr>
34 <tr οnmοuseοver="this.style.backgroundColor='#ffff66';" οnmοuseοut="this.style.backgroundColor='#d4e3e5';">
35     <td>Item 1A</td><td>Item 1B</td><td>Item 1C</td>
36 </tr>
37 <tr οnmοuseοver="this.style.backgroundColor='#ffff66';" οnmοuseοut="this.style.backgroundColor='#d4e3e5';">
38     <td>Item 2A</td><td>Item 2B</td><td>Item 2C</td>
39 </tr>
40 <tr οnmοuseοver="this.style.backgroundColor='#ffff66';" οnmοuseοut="this.style.backgroundColor='#d4e3e5';">
41     <td>Item 3A</td><td>Item 3B</td><td>Item 3C</td>
42 </tr>
43 <tr οnmοuseοver="this.style.backgroundColor='#ffff66';" οnmοuseοut="this.style.backgroundColor='#d4e3e5';">
44     <td>Item 4A</td><td>Item 4B</td><td>Item 4C</td>
45 </tr>
46 <tr οnmοuseοver="this.style.backgroundColor='#ffff66';" οnmοuseοut="this.style.backgroundColor='#d4e3e5';">
47     <td>Item 5A</td><td>Item 5B</td><td>Item 5C</td>
48 </tr>
49 </table>
复制代码

 

转载于:https://www.cnblogs.com/borter/p/9480211.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/125360.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 如何将Java完全卸载

    之前安装的Java没有卸载干净,造成重新安装JDK能正常安装,接着安装JRE的时候总是报1603错误。虽然说JRE安装报错了没安装上,但是eclipse、IntelliJIDEA和AndroidStudio都能正常打开和使用,然而在命令行里却无法使用。虽然工具能正常打开,但是这不能忍,为此我差点就直接使用狂暴AOE秒杀大招重装系统了,还好,最后解决了。在这里,我分享一下我是如何解决的,有需要的小…

    2022年4月3日
    1.4K
  • FQDN_dns资源记录类型有哪些

    FQDN_dns资源记录类型有哪些FQDN全域名(FQDN,FullyQualifiedDomainName)是指主机名加上全路径,全路径中列出了序列中所有域成员。全域名可以从逻辑上准确地表示出主机在什么地方,也可以说全域名是主机名的一种完全表示形式。从全域名中包含的信息可以看出主机在域名树中的位置。例如,acmecompany公司的Web服务器的全域名可以是[url]www.acmecom…

    2025年8月16日
    1
  • GateWay 网关跨域问题「建议收藏」

    GateWay 网关跨域问题「建议收藏」yml文件中配置即可:spring:cloud:gateway:globalcors:#全局的跨域处理add-to-simple-url-handler-mapping:true#解决options请求被拦截问题corsConfigurations:'[/**]’:allowedOrigins:#允许哪些网站的跨域请求allowedOrigins:“*”允许所有网站…

    2022年10月9日
    3
  • 编译原理之代码生成「建议收藏」

    前面提到了经过了词法分析->语法分析->语义分析->中间代码优化,最后的阶段便是在目标机器上运行的目标代码的生成了。目标代码生成阶段的任务是:将此前的中间代码转换成特定机器上的机器语言或汇编语言,这种转换程序便被称为代码生成器。1.程序移植性和编译器模块设计的关系之所以将编译原理分成这种多阶段多模块的组织形式,本质的考虑其实只有两个方面:一、代码复用:尽可能在不增加程序员工作量的前提下,增

    2022年4月10日
    50
  • snmp trap日志「建议收藏」

    snmp trap日志「建议收藏」日志类型有三种,file,syslog和snmptrapsnmptrapd.conf文件内容及参数snmptrapd手册:http://www.net-snmp.org/docs/man/snmptrapd.conf.html,http://www.net-snmp.org/wiki/index.php/Snmptrapd中文翻译:《snmptrapd.conf文件内容及参数》,而且详细列出了参数《SnmpTrap的发送和接收演示》IBM开发者网站关于snmptrap引用最.

    2022年8月20日
    24
  • 微信开发者工具程序开发好后,不报错,但是黑屏「建议收藏」

    微信开发者工具程序开发好后,不报错,但是黑屏「建议收藏」微信开发者工具程序开发好后,不报错,但是黑屏

    2022年4月24日
    55

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号