当前位置:Gxlcms > css > css怎么设置表格样式?css设置表格样式的方法

css怎么设置表格样式?css设置表格样式的方法

时间:2021-07-01 10:21:17 帮助过:81人阅读

一个简单的表格有时会感觉很单调,那么怎么给css表格加样式呢?本篇文章就给大家介绍关于css表格样式的设置方法。

1、一个简单的表格
table.html

  1. <!doctype html><html><head>
  2. <meta charset="utf-8">
  3. <title>表格样式</title>
  4. <link href="box.css" type="text/css" rel="stylesheet"></head><body>
  5. <center>
  6. <table class="class">
  7. <caption>课程表</caption>
  8. <tr>
  9. <th>星期\课程</th>
  10. <th>星期一</th>
  11. <th>星期二</th>
  12. <th>星期三</th>
  13. <th>星期四</th>
  14. <th>星期五</th>
  15. </tr>
  16. <tr>
  17. <th>1-2节</th>
  18. <td>数学</td>
  19. <td>语文</td>
  20. <td>化学</td>
  21. <td>英语</td>
  22. <td>英语</td>
  23. </tr>
  24. <tr>
  25. <th>3-4节</th>
  26. <td>英语</td>
  27. <td>物理</td>
  28. <td>化学</td>
  29. <td>英语</td>
  30. <td>体育</td>
  31. </tr>
  32. <tr>
  33. <th>5-6节</th>
  34. <td>数学</td>
  35. <td>物理</td>
  36. <td>体育</td>
  37. <td>化学</td>
  38. <td>美术</td>
  39. </tr>
  40. <tr>
  41. <th>7-8节</th>
  42. <td>数学</td>
  43. <td>美术</td>
  44. <td>化学</td>
  45. <td>英语</td>
  46. <td>体育</td>
  47. </tr>
  48. <tr>
  49. <th>9-10节</th>
  50. <td>生物</td>
  51. <td>美术</td>
  52. <td>生物</td>
  53. <td>英语</td>
  54. <td>物理</td>
  55. </tr>
  56. </table>
  57. </center>
  58. </body></html>

table.css

  1. table,td,th{
  2. border:1px solid #aaa;
  3. font-size: 23px;
  4. }

2、边框合并:boder-collapse
属性值:
separate;(分开,默认)
collapse;(合并)

table.css

  1. table,td,th{
  2. border:1px solid #aaa;
  3. font-size: 23px;
  4. border-collapse:collapse;
  5. }

3、边框间距border-spacing(前提是:border-collapse:separate;)

table.css

  1. table,td,th{
  2. border:1px solid #aaa;
  3. font-size: 23px;
  4. border-collapse:separate;
  5. border-spacing: 45px;
  6. }

4、设置表格标题的位置caption-side
属性值:
top;//默认
bottom;
left;
right;

table.css

  1. table,td,th{
  2. border:1px solid #aaa;
  3. font-size: 23px;
  4. border-collapse:separate;
  5. border-spacing: 45px;
  6. caption-side:bottom;
  7. }

5、当单元格对象宽度超过单元格所定义的宽度时,可用table-layout:fixed保持表格宽度不被改变
属性值:auto(默认)
fixed(宽度固定)
table.css

  1. table,td,th{
  2. border:1px solid #aaa;
  3. font-size: 23px;
  4. border-collapse:separate;
  5. border-spacing: 5px;
  6. table-layout: fixed;
  7. caption-side:top;
  8. }

相关推荐:

CSS控制表格样式_html/css_WEB-ITnose

精通CSS+DIV网页样式与布局设置表单和表格_html/css_WEB-ITnose

Css基本样式表格的详细介绍

以上就是css怎么设置表格样式?css设置表格样式的方法的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行