当前位置:   article > 正文

四个好看的CSS样式表格_css 黑色风格 表格

css 黑色风格 表格

http://blog.csdn.net/nightelve/article/details/7957726/

 

 

1. 单像素边框CSS表格

 

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

  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. <!-- Table goes in the document BODY -->
  27. <table class="gridtable">
  28. <tr>
  29. <th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
  30. </tr>
  31. <tr>
  32. <td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
  33. </tr>
  34. <tr>
  35. <td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
  36. </tr>
  37. </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">
  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. <!-- Table goes in the document BODY -->
  27. <table class="imagetable">
  28. <tr>
  29. <th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
  30. </tr>
  31. <tr>
  32. <td>Text 1A</td><td>Text 1B</td><td>Text 1C</td>
  33. </tr>
  34. <tr>
  35. <td>Text 2A</td><td>Text 2B</td><td>Text 2C</td>
  36. </tr>
  37. </table>

 

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

 

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

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

 

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

  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. <!-- Table goes in the document BODY -->
  29. <table class="hovertable">
  30. <tr>
  31. <th>Info Header 1</th><th>Info Header 2</th><th>Info Header 3</th>
  32. </tr>
  33. <tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
  34. <td>Item 1A</td><td>Item 1B</td><td>Item 1C</td>
  35. </tr>
  36. <tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
  37. <td>Item 2A</td><td>Item 2B</td><td>Item 2C</td>
  38. </tr>
  39. <tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
  40. <td>Item 3A</td><td>Item 3B</td><td>Item 3C</td>
  41. </tr>
  42. <tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
  43. <td>Item 4A</td><td>Item 4B</td><td>Item 4C</td>
  44. </tr>
  45. <tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
  46. <td>Item 5A</td><td>Item 5B</td><td>Item 5C</td>
  47. </tr>
  48. </table>

 

 

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读