2_rem与em.html 871 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. html{
  13. font-size: 20px;
  14. }
  15. /* rem 相对于根元素(html)的字体大小 */
  16. .box{
  17. width: 10rem;
  18. height: 10rem;
  19. background-color: red;
  20. }
  21. .div1{
  22. font-size: 30px;
  23. }
  24. /* em 相对于本身 及 祖先元素的font-size */
  25. .div2{
  26. font-size: 20px;
  27. width: 10em;
  28. height: 10em;
  29. background-color: blue;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div class="box"></div>
  35. <div class="div1">
  36. <div class="div2"></div>
  37. </div>
  38. </body>
  39. </html>