Blogger Information
Blog 14
fans 0
comment 0
visits 8299
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
rem+vw布局原理和grid布局学习
#三生
Original
551 people have browsed it

1. rem+vw布局原理

简单说明:
  • vw 相对于视口的宽度。视口被均分为100单位的vw
  • vh 相对于视口的高度。视口被均分为100单位的vh
  • calc 是 css3提供的一个在css文件中计算值的函数:用于动态计算长度值。
  • calc()函数支持 “+”, “-“, “*”, “/“ 运算;
  • calc(100vh - 10px) 表示整个浏览器窗口高度减去10px的大小
  • calc(100vw - 10px) 表示整个浏览器窗口宽度减去10px的大小
  • 1rem = 100px
代码演示:
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. <style>
  9. * {
  10. padding: 0;
  11. margin: 0;
  12. box-sizing: border-box;
  13. }
  14. html {
  15. font-size: calc(100vw / 3.75);
  16. }
  17. body {
  18. position: relative;
  19. font-size: 0.13rem;
  20. color: #505050;
  21. background: #fff;
  22. height: 100vh;
  23. }
  24. @media screen and (max-width: 320px) {
  25. html {
  26. font-size: 85px;
  27. }
  28. }
  29. @media screen and (min-width: 640px) {
  30. html {
  31. font-size: 170px;
  32. }
  33. }
  34. .container {
  35. width: 2rem;
  36. margin: 0 auto;
  37. }
  38. h2 {
  39. text-align: center;
  40. }
  41. .form-control {
  42. width: 2rem;
  43. height: 0.23rem;
  44. }
  45. .form-group,
  46. .btn {
  47. margin-top: 0.1rem;
  48. }
  49. .form-group>.label {
  50. display: block;
  51. }
  52. .form-group>.form-control {
  53. border: 1px solid #bfc0c5;
  54. }
  55. .form-group>.form-control:hover {
  56. border: 1px solid #474d5b;
  57. color: #383e4b;
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <div class="container">
  63. <h2>注 册</h2>
  64. <form action="php.html">
  65. <div class="form-group">
  66. <label class="label" for="name">用户名:</label>
  67. <input type="text" class="form-control" id="name" placeholder="请输入用户名" />
  68. </div>
  69. <div class="form-group">
  70. <label class="label" for="password">密码</label>
  71. <input type="password" class="form-control" id="password" placeholder="请输入密码" />
  72. </div>
  73. <div class="form-group">
  74. <label class="label" for="email">Email</label>
  75. <input type="email" class="form-control" id="email" placeholder="请输入Email" />
  76. </div>
  77. <div class="form-group">
  78. <input class="form-checkbox" id="checkbox" type="checkbox" value="value" />
  79. <label class="labelb" for="checkbox">勾选登录</label>
  80. </div>
  81. <button type="button" class="btn">登录</button>
  82. </form>
  83. </div>
  84. </body>
  85. </html>
示例图:

2. 实例演示grid布局中的所有属性

简单说明:
  • 使用 CSS Grid布局首要的第一步,就是通过 display:grid; 来对容器声明一个网格容器,那么这个 div 元素里面对应的子元素就自动成为网格项目
  • grid-template-columns 属性用于设置网格布局中的列数及宽度
  • grid-template-rows 属性用于设置网格布局中的行数及高度
  • grid-gap 用来指定列(或行)的间距
  • fr 可以自动根据网格容器的宽度来计算列的宽度
代码演示:
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>布局(grid版)</title>
  8. <style>
  9. * {
  10. padding: 0;
  11. margin: 0;
  12. box-sizing: border-box;
  13. }
  14. body {
  15. background-color: rgb(210, 221, 210);
  16. }
  17. .grid {
  18. width: 100vm;
  19. height: 100vh;
  20. display: grid;
  21. gap: 10px 10px;
  22. grid-template-columns: 1fr 4fr;
  23. grid-template-rows: 100%;
  24. }
  25. .left {
  26. display: grid;
  27. grid-template-columns: 1fr;
  28. grid-row-gap: 10px;
  29. }
  30. .left>.lb {
  31. display: grid;
  32. grid-template-columns: 1fr 1fr;
  33. gap: 10px 10px;
  34. }
  35. .right {
  36. display: grid;
  37. grid-template-columns: 1fr;
  38. gap: 10px;
  39. grid-template-rows: 30%;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div class="grid">
  45. <div class="left">
  46. <div class="lt" style="background-color: #f78783">1</div>
  47. <div class="lb">
  48. <div style="background-color: #9983ce">3</div>
  49. <div style="background-color: #7ec42f">5</div>
  50. </div>
  51. </div>
  52. <div class="right">
  53. <div style="background-color: #dd34b3">2</div>
  54. <div style="background-color: #d8ee12">4</div>
  55. </div>
  56. </div>
  57. </body>
  58. </html>
示例图:

Correcting teacher:PHPzPHPz

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