Blogger Information
Blog 56
fans 0
comment 4
visits 38083
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
绝对单位px和相对单位:em,rem,vh,vw和布局演示
异乡客
Original
551 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>常用单位</title>
  8. </head>
  9. <body>
  10. <!-- <header>header</header>
  11. <aside class="left">left</aside>
  12. <main>main</main>
  13. <aside class="right">right</aside>
  14. <footer>footer</footer> -->
  15. <header>header</header>
  16. <aside class="left">left</aside>
  17. <main>main</main>
  18. <aside class="right">right</aside>
  19. <footer>footer</footer>
  20. <style>
  21. /* * {
  22. padding: 0;
  23. margin: 0;
  24. box-sizing: border-box;
  25. } */
  26. * {
  27. padding: 0;
  28. margin: 0;
  29. box-sizing: border-box;
  30. }
  31. /* body {
  32. display: grid;
  33. grid-template-rows: 2em minmax(20em, 30em) 2em;
  34. grid-template-columns: 6em 1fr 6em;
  35. } */
  36. body {
  37. display: grid;
  38. grid-template-columns: 6em 1fr 6em;
  39. grid-template-rows: 2em minmax(20em, 30em) 2em;
  40. }
  41. header,
  42. footer {
  43. /* height: 2em; */
  44. background-color: rgb(72, 255, 0);
  45. }
  46. aside {
  47. background-color: coral;
  48. }
  49. main {
  50. background-color: turquoise;
  51. }
  52. footer,
  53. header {
  54. grid-column: span 3;
  55. }
  56. </style>
  57. </body>
  58. </html>

  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>常用单位</title>
  8. </head>
  9. <body>
  10. <!-- px,em,rem,vh,vw -->
  11. <!-- 相对单位:em,rem,vh,vw -->
  12. <div class="box"></div>
  13. <div class="box1"></div>
  14. <div class="box2"></div>
  15. </body>
  16. </html>
  17. <style>
  18. .box {
  19. font-size: 20px;
  20. width: 10em;
  21. /* 1em=16px 永远和当前或父级的font-size进行绑定*/
  22. /* em= font-size */
  23. height: 15em;
  24. border: 10px dashed currentColor;
  25. background-color: hotpink;
  26. background-clip: content-box;
  27. padding: 20px;
  28. /* padding: 内边距,看不见的,呼吸区; */
  29. /* 当前盒子的总宽度:200+20*2+10*2=260px ,这种布局改变了原来想要的盒子大小,影响布局*/
  30. /* 因此需要改变盒子大小的计算方式,使用户设置width,height就是盒子的实际大小,以方便计算 */
  31. box-sizing: border-box;
  32. margin: 5px;
  33. /* 此时width,height就是最终的盒子大小,内容压缩了 */
  34. }
  35. .box1 {
  36. font-size: 40px;
  37. /* rem:永远和html中的font-size绑定 */
  38. width: 10rem;
  39. height: 15rem;
  40. border: 10px dashed currentColor;
  41. background-color: hotpink;
  42. background-clip: content-box;
  43. padding: 20px;
  44. box-sizing: border-box;
  45. margin: 5px;
  46. }
  47. .box2 {
  48. font-size: 40px;
  49. /* vw将视口宽度分为100分,1vm=1/100 */
  50. /* vh将视口高度分为100分,1vm=1/100 */
  51. width: 50vw;
  52. height: 50vh;
  53. border: 10px dashed currentColor;
  54. background-color: hotpink;
  55. background-clip: content-box;
  56. padding: 20px;
  57. box-sizing: border-box;
  58. margin: 5px;
  59. }
  60. html {
  61. font-size: 10px;
  62. }
  63. </style>
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