博客列表 >em vem的应用场景

em vem的应用场景

心
原创
2020年12月21日 17:37:29542浏览

em和vem 的应用场景

  1. em 是font-size 的倍数
  2. 1em 在没有设置字体的时候 浏览器默认是 16px;
  3. 当文本里面使用 font-size 时 1em 就等于 font-size 的值
  4. em 设置响应式的文本字号
  5. font-size 是允许被继承
  6. 可以设置响应式盒模型
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8>
  5. <title>em的应用</title>
  6. <style>
  7. html{
  8. font-size:20px;
  9. }
  10. /*现在的h2字体的大小是 30px*/
  11. h2{
  12. font-size:1.5em;
  13. }
  14. div{
  15. /*现在盒子的大小是 宽200px*高400px*/
  16. width:10em;
  17. height:20em;
  18. }
  19. div{
  20. /*现在的盒子大小是 宽400px*高800ox*/
  21. font-size:40px;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <h2>你好php</h2>
  27. <div></div>
  28. </body>
  29. </html>

按钮的案例

  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>按钮</title>
  7. <style>
  8. /* 基本样式 */
  9. .btn{
  10. background-color: blue;
  11. color:#fff;
  12. border:none;
  13. outline: none;
  14. padding: 0.5em 1em;
  15. /* 圆角 */
  16. border-radius: 0.2em;
  17. }
  18. .btn:hover{
  19. /* 透明度 */
  20. opacity:0.8 ;
  21. /* 将鼠标设置为手型 */
  22. cursor: pointer;
  23. box-shadow: 0 0 3px #888;
  24. transition: 0.3s;
  25. }
  26. /* 如果想设置三个不同的大小按钮,只需要为这个三个按钮指定不同的自号就可以了 */
  27. /* 较小的 */
  28. .small{
  29. font-size: 10px;
  30. }
  31. /* 正常的 */
  32. .normal{
  33. font-size: 16px;
  34. }
  35. /* 较大的 */
  36. .lar{
  37. font-size:20px;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <button class="btn small">button</button>
  43. <button class="btn nomal">button</button>
  44. <button class="btn lar">button</button>
  45. </body>
  46. </html>

em定义字号

  1. em具有动态性 和继承性
  2. rem 是固定值的 em
  3. rem 是根元素的字号大小
  4. 边框不能用em
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta chaset="utf-8>
  5. <title>rem的应用</title>
  6. <style>
  7. html是最顶级元素
  8. html{
  9. /*在字体大小是32px */
  10. font-size:2em;
  11. }
  12. h2{
  13. /*字体大小是1.5*32=48px*/
  14. font-size:1.5em
  15. }
  16. span{
  17. /*字体大小是32px*/
  18. font-size:2rem;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <h2>你好 php<span>中文网</span></h2>
  24. </body>
  25. </html>

vh 视口化的高度 1/100
vw 视口化的宽度 1/100

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议