Blogger Information
Blog 25
fans 1
comment 0
visits 12986
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
grid和flex布局结合vw-rem布局实际应用
xueblog9的进阶之旅
Original
327 people have browsed it

grid和flex布局结合vw-rem布局实际应用

布局实际应用

html源码

  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>vw-rem案例</title>
  8. <link rel="stylesheet" href="./css/header.css">
  9. <link rel="stylesheet" href="./css/main.css">
  10. </head>
  11. <body>
  12. <header>
  13. <div class="top">
  14. <div class="sky">
  15. <span>PHP中文网,程序员梦开始的地方!</span>
  16. <a href="" class="iconfont icon-tongzhi tongzhi"></a>
  17. <a href="" class="pic"><img src="./css/images/user-pic.jpeg" alt=""></a>
  18. </div>
  19. <civ class="navs">
  20. <a href=""><img src="./css/images/logo.png" alt=""></a>
  21. <a href="">首页</a>
  22. <a href="">视频教程</a>
  23. <a href="">学习路径</a>
  24. <a href="">php培训</a>
  25. <a href="">资源下载</a>
  26. <a href="">技术文章</a>
  27. <a href="">社区</a>
  28. <a href="">app下载</a>
  29. <div class="search">
  30. <input type="search" class="sech" placeholder="输入关键字">
  31. <label for="sech">搜索</label>
  32. </div>
  33. </div>
  34. </div>
  35. </header>
  36. <main class="main">
  37. <div class="content">
  38. <div class="left">
  39. <a href="">php开发</a>
  40. <a href="">大前端</a>
  41. <a href="">后端开发</a>
  42. <a href="">数据库</a>
  43. <a href="">移动端</a>
  44. <a href="">运维开发</a>
  45. <a href="">UI设计</a>
  46. <a href="">计算机基础</a>
  47. </div>
  48. <div class="mid">
  49. <a href=""><img src="./css/images/slider.jpeg" alt=""></a>
  50. </div>
  51. <div class="right">
  52. <div class="userinfo">
  53. <a href=""><img src="./css/images/user-pic.jpeg" alt=""></a>
  54. <div class="name"><a href="">朱老师</a></div>
  55. <div class="button"><a href="">我的学习</a></div>
  56. <div class="info">p豆 2065.5</div>
  57. </div>
  58. <ul class="nav-right">
  59. <li class="content1">问答社区</li>
  60. <li class="content2">头条</li>
  61. <li class="content3">福利</li>
  62. <li class="content4">新班</li>
  63. <li class="content5">招募</li>
  64. <li class="content6">公告</li>
  65. <li class="content7"><a href="">答疑</a></li>
  66. <li class="content8"><a href="">【整理分享】2022年最流行的</a></li>
  67. <li class="content9"><a href="">限时折扣>></a></li>
  68. <li class="content10"><a href="">20期PHP线上班</a></li>
  69. <li class="content11"><a href="">课程合作计划</a></li>
  70. <li class="content12"><a href="">app上线啦</a></li>
  71. </ul>
  72. </div>
  73. <div class="buttom-left">
  74. <ul class="navbottom">
  75. <li>
  76. <span>学习路径</span>
  77. <span>全部7个&gt;</span>
  78. </li>
  79. <li>
  80. <img width="50px" src="./css/images/dgjj.png" alt="">
  81. <a href="">独孤九剑</a>
  82. <span>9门课程</span>
  83. </li>
  84. <li>
  85. <img width="50px" src="./css/images/phpkjkf.png" alt="">
  86. <a href="">独孤九剑</a>
  87. <span>9门课程</span>
  88. </li>
  89. <li>
  90. <img width="50px" src="./css/images/phpksrm.png" alt="">
  91. <a href="">独孤九剑</a>
  92. <span>9门课程</span>
  93. </li>
  94. <li>
  95. <img width="50px" src="./css/images/tlbb.png" alt="">
  96. <a href="">独孤九剑</a>
  97. <span>9门课程</span>
  98. </li>
  99. <li><img width="50px" src="./css/images/ynxj.png" alt="">
  100. <a href="">独孤九剑</a>
  101. <span>9门课程</span>
  102. </li>
  103. </ul>
  104. </div>
  105. </div>
  106. </main>
  107. </body>
  108. </html>

css源码

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. a {
  7. text-decoration: none;
  8. color: #555;
  9. }
  10. body {
  11. background-color: rgb(243, 245, 247);
  12. }
  13. li {
  14. list-style: none;
  15. }
  16. body {
  17. background-color: #f3f5f7;
  18. }
  19. header .top {
  20. width: 100vw;
  21. height: 40px;
  22. background-color: #343434;
  23. color: #aaa;
  24. }
  25. header .top .content {
  26. /* 必须限定宽高,否则无法在父容器中居中 */
  27. width: 1200px;
  28. display: grid;
  29. grid-template-columns: 400px 100px;
  30. grid-auto-rows: 40px;
  31. place-content: space-between;
  32. place-items: center start;
  33. margin: auto;
  34. }
  35. /* 钟图标 */
  36. header .top .content .right .iconfont {
  37. color: #eee;
  38. font-size: larger;
  39. }
  40. /* 头像 */
  41. header .top .content img {
  42. width: 50%;
  43. border-radius: 50%;
  44. }
  45. header .top .content .right {
  46. display: grid;
  47. grid-template-columns: repeat(2, 1fr);
  48. place-items: center;
  49. }
  50. header .top .content .title {
  51. font-size: larger;
  52. /* 加粗 */
  53. font-weight: larger;
  54. }
  55. /* 导航 */
  56. header .navs {
  57. width: 100vw;
  58. height: 90px;
  59. background-color: #fff;
  60. box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  61. }
  62. header .navs .content {
  63. /* 必须限定宽高,否则无法在父容器中居中 */
  64. width: 1200px;
  65. display: grid;
  66. grid-template-columns: 140px 1fr 200px;
  67. grid-auto-rows: 90px;
  68. margin: auto;
  69. gap: 10px;
  70. place-items: center start;
  71. }
  72. header .navs .content nav {
  73. display: flex;
  74. }
  75. header .navs .content nav a {
  76. padding: 0 10px;
  77. }
  78. header .navs .content nav a:hover,
  79. header .navs .content nav a.active {
  80. font-weight: bold;
  81. color: red;
  82. }
  83. header .navs .content img {
  84. width: 100%;
  85. }
  86. header .navs .content .search {
  87. display: flex;
  88. }
  89. header .navs .content .search input[type='search'] {
  90. width: 200px;
  91. height: 36px;
  92. border: none;
  93. background-color: #eee;
  94. outline: none;
  95. border-radius: 20px;
  96. padding-left: 10px;
  97. }
  98. header .navs .content .search .icon-fangdajing1 {
  99. font-size: 22px;
  100. color: #ccc;
  101. position: relative;
  102. left: -40px;
  103. top: 5px;
  104. }
  105. header .navs .content .search .icon-fangdajing1:hover {
  106. color: red;
  107. /* 小手 */
  108. cursor: pointer;
  109. }
  110. /*header结束*/
  111. body main {
  112. display: grid;
  113. place-content: center;
  114. padding-top: 2vh;
  115. }
  116. body main .content {
  117. display: grid;
  118. width: 70vw;
  119. height: 54vh;
  120. grid-template-columns: 8vw 42vw 14vw;
  121. grid-template-rows: 38vh 12vh;
  122. /* border: 1px solid black; */
  123. place-content: space-evenly;
  124. }
  125. body main .content .left {
  126. display: flex;
  127. flex-direction: column;
  128. place-content: space-around;
  129. place-items: center;
  130. padding-top: 2vh;
  131. padding-bottom: 2vh;
  132. font-size: 0.11rem;
  133. background-color: white;
  134. border-radius: 20px;
  135. }
  136. body main .content .left a:hover {
  137. color: red;
  138. }
  139. body main .content .mid {
  140. display: grid;
  141. place-content: center;
  142. }
  143. body main .content .mid a img {
  144. width: 100%;
  145. border-radius: 0.2rem;
  146. padding: 0.1rem;
  147. }
  148. /* 右侧上头 */
  149. body main .content .right {
  150. background-color: white;
  151. border-radius: 20px;
  152. }
  153. body main .content .right .userinfo {
  154. display: grid;
  155. grid-template-columns: 5vw 7vw;
  156. grid-template-rows: 4vh 4vh 4vh;
  157. place-content: center;
  158. place-items: center;
  159. border-bottom: 1px solid #bbb;
  160. padding-bottom: 1vh;
  161. padding-top: 1vh;
  162. }
  163. body main .content .right .userinfo a {
  164. grid-area: 1 / 1 / span 2 / span 1;
  165. place-self: center end;
  166. }
  167. /* 头像2 */
  168. body main .content .right .userinfo a img {
  169. width: 4vw;
  170. border-radius: 20px;
  171. }
  172. body main .content .right .userinfo .name {
  173. width: 4vw;
  174. border-radius: 20px;
  175. font-size: 0.09rem;
  176. place-self: end center;
  177. font-weight: bold;
  178. }
  179. body main .content .right .userinfo .button {
  180. grid-column: 1 / 3;
  181. grid-row: 3 / 4;
  182. background-color: red;
  183. width: 10vw;
  184. border-radius: 20px;
  185. text-align: center;
  186. }
  187. body main .content .right .userinfo .button a {
  188. color: white;
  189. font-size: smaller;
  190. }
  191. body main .content .right .userinfo .info {
  192. font-size: 0.09rem;
  193. place-self: start center;
  194. }
  195. /* 头像部分结束 */
  196. /* 右侧底部菜单栏 */
  197. body main .content .right .nav-right {
  198. display: grid;
  199. grid-template-columns: 5vw 7vw;
  200. grid-template-rows: repeat(6,3.3vh);
  201. grid-auto-flow: column;
  202. place-content: center;
  203. place-items: center;
  204. font-size: 0.1rem;
  205. padding-top: 2vh;
  206. }
  207. body main .content .buttom-left {
  208. grid-column: 1 / 3;
  209. grid-row: 2 / 3;
  210. }
  211. body main .content .buttom-left .navbottom {
  212. display: flex;
  213. place-items: center;
  214. place-content: space-around;
  215. font-size: 0.10rem;
  216. padding: 0.1rem;
  217. }
  218. body main .content .buttom-left .navbottom li:nth-of-type(n+2) {
  219. display: grid;
  220. grid-template-columns: 3vw 4vw;
  221. gap: 0 10px;
  222. place-items: center start;
  223. padding-left: 0.1rem;
  224. }
  225. body main .content .buttom-left .navbottom img {
  226. grid-row: span 2;
  227. }
  228. body main .content .buttom-left .navbottom li:nth-of-type(1) {
  229. display: flex;
  230. flex-direction: column;
  231. place-content: center;
  232. }
  233. body main .content .buttom-left .navbottom li:nth-of-type(n+2) a {
  234. font-weight: bold;
  235. color: black;
  236. }
  237. body main .content .buttom-left .navbottom li:nth-of-type(n+2) a:hover {
  238. color: red;
  239. }
  240. body main .content .buttom-left .navbottom li:nth-of-type(n+2) span {
  241. color: #555;
  242. }

实际效果:

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