Blogger Information
Blog 21
fans 0
comment 0
visits 10051
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1024用rem + vw 重写 课程表 案例, css中不出现px
放手去爱
Original
285 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>rem/em/vw/vh单位学习示例</title>
  8. <style>
  9. /* em:继承字号,受自身和祖先影响
  10. rem:根字号,字号常量不变
  11. PC端:用em 比较多
  12. 移动端:用rem 比较多
  13. */
  14. /*
  15. 因为font-size可以继承,写到父级与写到当前元素有区别
  16. 因为em受到了当前元素和祖先元素font-size 字号的影响
  17. 解决这个问题,最好引用一个不变的字号常量
  18. 这个不变的字号常量就是根字号 `rem`
  19. * ! em : 继承字号
  20. rem 根字号,默认是16px,除非人为更 新,否则不变
  21. **/
  22. /*
  23. vw/vh:视口单位
  24. 视口: viewport 可视窗口,当前文档(html)的可见部分
  25. 视口单位:vw , vh
  26. vw:viewport-width 视口宽度
  27. vh:viewport-height 视口高度
  28. 1vw = 1 / 100 (视口宽度 window.innerWidth )
  29. 1vh = 1 / 100 (视口高度 window.innerHeight )
  30. 和百分比 % 非常像
  31. 1. % : 以父级元素宽高为参照物
  32. 2. vw / vh : 以视口宽高为参照物
  33. */
  34. :root{1rem;}
  35. /* 表格文本居中 ,拆叠td 双线 宽度*/
  36. table {text-align: center;border-collapse: collapse;width: 90vw;}
  37. /* 设置边框 */
  38. table td, table th, table caption {border:1px solid #000000;}
  39. /* 行高 */
  40. table tr,table caption {height: 2.2rem; line-height: 2.2rem;}
  41. /* td宽度 */
  42. table td{width:8rem;}
  43. /* 头部标题字号和背景颜色字体颜色 */
  44. table caption{font-size:2em;background: #72e7ca;color: red;}
  45. /* 给thead 添加颜色 */
  46. table thead{background-color: aqua;}
  47. /* table tbody tr:first-of-type td:first-of-type 用tbody 作用not 取反伪类 */
  48. table tbody:not(tbody:nth-of-type(0)) tr:first-of-type td:first-of-type{background-color: lightgreen;}
  49. /* 鼠标悬浮伪类 */
  50. table td:hover{cursor: pointer;background: #e97a9b;}
  51. </style>
  52. </head>
  53. <body>
  54. <table>
  55. <!-- 顶部标题 -->
  56. <caption>
  57. PHP.CN中文网学员上课表
  58. </caption>
  59. <!-- 头部标题 -->
  60. <thead>
  61. <tr>
  62. <th>时间</th>
  63. <th>周一</th>
  64. <th>周二</th>
  65. <th>周三</th>
  66. <th>周四</th>
  67. <th>周五</th>
  68. </tr>
  69. </thead>
  70. <!-- 上午tbody -->
  71. <tbody>
  72. <tr>
  73. <td rowspan="2">上午</td>
  74. <td>前端html</td>
  75. <td>CSS样式</td>
  76. <td>html5</td>
  77. <td>php开发</td>
  78. <td>TP6</td>
  79. </tr>
  80. <tr>
  81. <td>前端html</td>
  82. <td>CSS样式</td>
  83. <td>html5</td>
  84. <td>php开发</td>
  85. <td>TP6</td>
  86. </tr>
  87. </tbody>
  88. <tbody>
  89. <tr>
  90. <td rowspan="2">下午</td>
  91. <td>TP6</td>
  92. <td>php开发</td>
  93. <td>html5</td>
  94. <td>前端html</td>
  95. <td>CSS样式</td>
  96. </tr>
  97. <tr>
  98. <td>TP6</td>
  99. <td>php开发</td>
  100. <td>html5</td>
  101. <td>前端html</td>
  102. <td>CSS样式</td>
  103. </tr>
  104. </tbody>
  105. </table>
  106. </body>
  107. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:完成的效果不错,要是添加一个运行结果图就好了
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post