05.单位.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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>Document</title>
  8. <style>
  9. /*
  10. 长度单位:
  11. 像素
  12. -屏幕(显示器)实际上是由一个一个的小点点构成的
  13. -不同屏幕的像素大小是不同的,像素越小的屏幕显示的效果越清晰
  14. -所以同样的200px在不同的设备下,显示效果不一样
  15. 百分比
  16. -也可以将属性值设置为相对于其父元素属性的百分比
  17. -设置百分比,可以使子元素跟随父元素的改变而改变
  18. em
  19. -em是相对于元素的字体大小来计算的
  20. -1em = 1font-size(1font-size默认大小是16px)
  21. -em会根据字体大小的改变而改变
  22. rem
  23. -rem是相对于根元素的字体大小来计算
  24. */
  25. html{
  26. font-size: 20px;
  27. }
  28. .box1{
  29. width: 200px;
  30. height: 200px;
  31. background-color: orange;
  32. }
  33. .box2{
  34. width: 50%;
  35. height: 50%;
  36. background-color: blue;
  37. }
  38. /* .box3{
  39. font-size: 20px;
  40. width: 10em;
  41. height: 10em;
  42. background-color: yellowgreen;
  43. } */
  44. html{
  45. font-size: 20px;
  46. }
  47. .box3{
  48. font-size: 40px;
  49. width: 10rem;
  50. height: 10rem;
  51. background-color: greenyellow;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <!-- <div class="box1">
  57. <div class="box2"></div>
  58. </div> -->
  59. <div class="box3"></div>
  60. </body>
  61. </html>