使⽤html表格发送邮件--四个好看的CSS样式表格(⼆)1. 单像素边框CSS表格
这是⼀个很常⽤的表格样式。
源码:
1<!-- CSS goes in the document HEAD or added to your external stylesheet -->
2<style type="text/css">
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}
12 border-width: 1px;
13 padding: 8px;
14 border-style: solid;
15 border-color: #666666;
16 background-color: #dedede;
17}
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样式表格
和上⾯差不多,不过每个格⼦⾥多了背景图。
cell-blue.jpg
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">
3table.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}
11table.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}
18table.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样式表格⾃动切换每⼀⾏的颜⾊,在我们需要频繁更新⼀个⼤表格的时候很有⽤。
源码:
1<!-- Javascript goes in the document HEAD -->
2<script type="text/javascript">
3function altRows(id){
4 ElementsByTagName){
5
6 var table = ElementById(id);
7 var rows = ElementsByTagName("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
19window.ο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">
27table.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}
css表格样式35table.altrowstable th {
36 border-width: 1px;
37 padding: 8px;
38 border-style: solid;
39 border-color: #a9c6c9;
40}
41table.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: fixer/resources/css-tables.php#css-table03 -->
80
4. ⿏标悬停⾼亮的CSS样式表格 (需要JS)
纯CSS显⽰表格⾼亮在IE中显⽰有问题,所以这边使⽤了JS来做⾼亮(由于csdn博客限制了js的使⽤,我会在近期将博客迁移放到⾃⼰的web主机上)。
有⼀点要⼩⼼的是,不要定义格⼦的背景⾊。
1<!-- CSS goes in the document HEAD or added to your external stylesheet -->
2<style type="text/css">
3table.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}
11table.hovertable th {
12 background-color:#c3dde0;
13 border-width: 1px;
14 padding: 8px;
15 border-style: solid;
16 border-color: #a9c6c9;
17}
18table.hovertable tr {
19 background-color:#d4e3e5;
20}
21table.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>
最常见的⼏种CSS样式表格都在这了,希望对⼤家有帮助
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论