2.移动端单位.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. #box {
  13. width: 1rem;
  14. /* width: 200px; */
  15. /* height: 300px; */
  16. /* height: 10vh; */
  17. height: calc(500px - 10vh);
  18. background: #00f;
  19. color: red;
  20. font-size: 16px;
  21. }
  22. .aa {
  23. width: 100px;
  24. height: 2%;
  25. background: #ff0;
  26. }
  27. p {
  28. color:#fff;
  29. font-size: 1em;
  30. /* font-size: 20px; */
  31. /* text-indent: 2em; */
  32. }
  33. /*
  34. 单位
  35. px 像素
  36. % 百分比
  37. rem 根字体 1rem = 16px
  38. em 根据父级字体大小决定
  39. viewport
  40. vw : width 视口宽度
  41. vh: height 视口高度
  42. calc()
  43. */
  44. </style>
  45. </head>
  46. <body>
  47. <div id="box">
  48. 父级
  49. <p>
  50. 哈哈哈哈
  51. </p>
  52. <div class="aa"></div>
  53. </div>
  54. <script src="./rem.js"></script>
  55. </body>
  56. </html>