Blogger Information
Blog 11
fans 0
comment 1
visits 7828
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
em,rem,vw,vh的原理与应用场景
一代宗师
Original
1752 people have browsed it

em,rem的原理与应用场景

1.em:em通常用于依赖字号的元素属性上,比如margin、padding、width、height等元素;
2.rem:root em的缩写,通常用于font-size字号的设置上;
3.px:通常用于边框宽度border的设置上
4.em是根据它的父级来改变大小而rem只会随着root根元素的大小来改变

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>em,rem的原理与应用场景</title>
  7. <style>
  8. :root {
  9. font-size: 0.7em;
  10. }
  11. .news {
  12. background-color: #ccc;
  13. border: #000 solid 1px;
  14. padding: 1em;
  15. margin: 1em;
  16. }
  17. .news h2 {
  18. font-size: 3rem;
  19. }
  20. .news1 {
  21. font-size: 1.25rem;
  22. text-indent: 2em;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div class="news">
  28. <h2>1217作业</h2>
  29. <div class="news1">
  30. <p>按自己理解的方式详细描述em,rem的原理与应用场景 ,并实例演示 2. 分析 rem / em /vh/ vw的区别与联系</p>
  31. </div>
  32. </div>
  33. </body>
  34. </html>

vh,vw的应用

1、vw:表示视口的宽度,1vw就表示当前视口宽度的百分之一;
2、vh:表示视口的高度,1vh就表示当前视口高度的百分之一;
3、vmin:表示在vw与vh中取最小值;
4、vmax:表示在vw与vh中取最大值

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>vh/vw</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. .box1 {
  14. background-color: blue;
  15. width: 50vw;
  16. height: 25vh;
  17. }
  18. .box2 {
  19. background-color: coral;
  20. width: 50vw;
  21. height: 25vh;
  22. }
  23. .box3 {
  24. background-color: blanchedalmond;
  25. width: 50vw;
  26. height: 25vh;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="box1"></div>
  32. <div class="box2"></div>
  33. <div class="box3"></div>
  34. </body>
  35. </html>
Correcting teacher:天蓬老师天蓬老师

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