Blogger Information
Blog 21
fans 0
comment 0
visits 14738
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
em,rem,px的应用场景,区别与联系。vh,vw的使用
Yuming
Original
903 people have browsed it

em,rem,px的应用场景,区别与联系。vh,vw的使用

区别:px是固定像素,em是相对的长度单位相对于父元素,rem则相对于根元素<br/>
联系:相对的长度单位em 和 rem的出现一定有px的出现,他们之间存在相对的依赖关系

  • px我在写border的时候会用的比较多

    1. border:1px solide #eee;
  • 用rem的好处:当用rem做响应式时,直接在媒体查询中改变html的font-size的大小,那么用rem作为单位的元素大小都会相应的改变,很方便。

实例演示通过vh与vw实现浏览器自适应三行单列布局 [vh,vw的使用]

vh,vw是一种相对于视口的长度单位,平时也会偶尔用到,还是很方便的,另外vmin,vmax这两种就没那么常用了

  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. <link rel="stylesheet" href="test.css" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div class="box"></div>
  11. <div class="box"></div>
  12. <div class="box"></div>
  13. </body>
  14. </html>
  1. :root {
  2. height: 100vh;
  3. background-color: #eee;
  4. }
  5. .box:nth-child(1) {
  6. height: 33vh;
  7. background-color: red;
  8. }
  9. .box:nth-child(2) {
  10. height: 33vh;
  11. background-color: green;
  12. }
  13. .box:nth-child(3) {
  14. height: 33vh;
  15. background-color: blue;
  16. }

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