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

grid和flex布局实际应用

布局实际应用

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>grid: 仿PHP.CN首页</title>
  8. <!-- <link rel="stylesheet" href="icon-font.css" /> -->
  9. <link rel="stylesheet" href="https://at.alicdn.com/t/font_3205780_7eqow85axa.css" />
  10. <link rel="stylesheet" href="static/css/header.css" />
  11. <link rel="stylesheet" href="static/css/main-nav.css" />
  12. </head>
  13. <body>
  14. <!-- 页眉 -->
  15. <header>
  16. <!-- 顶部 -->
  17. <div class="top">
  18. <div class="content">
  19. <!-- 左边:顶部标题 -->
  20. <div class="title">php中文网,程序员梦开始的地方!</div>
  21. <!-- 右边: 用户信息 -->
  22. <div class="right">
  23. <a href="" class="iconfont icon-tixingtianchong"></a>
  24. <a href=""><img src="static/images/user-pic.jpeg" alt="" /></a>
  25. </div>
  26. </div>
  27. </div>
  28. <!-- 导航 -->
  29. <div class="navs">
  30. <div class="content">
  31. <a href="" class="logo"><img src="static/images/logo.png" alt="" /></a>
  32. <nav>
  33. <a href="" class="`active">首页</a>
  34. <a href="">视频教程</a>
  35. <a href="">学习路径</a>
  36. <a href="">php培训</a>
  37. <a href="">资源下载</a>
  38. </nav>
  39. <div class="search">
  40. <input type="search" placeholder="输入关键字" />
  41. <span class="iconfont icon-fangdajing1"></span>
  42. </div>
  43. </div>
  44. </div>
  45. </header>
  46. <!-- 主体 -->
  47. <main>
  48. <div class="navs">
  49. <div class="left">
  50. <a href="">php开发</a>
  51. <a href="">大前端</a>
  52. <a href="">后端开发</a>
  53. <a href="">数据库</a>
  54. <a href="">移动端</a>
  55. <a href="">运维开发</a>
  56. <a href="">UI设计</a>
  57. <a href="">计算机基础</a>
  58. </div>
  59. <div class="slider">
  60. <a href=""><img src="static/images/slider.jpeg" alt="" /></a>
  61. </div>
  62. <div class="right">
  63. <div class="userinfo">
  64. <a href=""><img src="static/images/user-pic.jpeg" alt=""></a>
  65. <div class="name"><a href="">朱 老 师</a></div>
  66. <div class="button"><a href="">我的学习</a></div>
  67. <div class="info">p豆 2065.5</div>
  68. </div>
  69. <ul class="tab">
  70. <li class="content1">问答社区</li>
  71. <li class="content2">头条</li>
  72. <li class="content3">福利</li>
  73. <li class="content4">新班</li>
  74. <li class="content5">招募</li>
  75. <li class="content6">公告</li>
  76. <li class="content7"><a href="">答疑</a></li>
  77. <li class="content8"><a href="">【整理分享】2022年最流行的</a></li>
  78. <li class="content9"><a href="">限时折扣>></a></li>
  79. <li class="content10"><a href="">20期PHP线上班</a></li>
  80. <li class="content11"><a href="">课程合作计划</a></li>
  81. <li class="content12"><a href="">app上线啦</a></li>
  82. </ul>
  83. </div>
  84. <div class="bottom-left">
  85. <div class="desc">
  86. <div class="title">学习路径</div>
  87. <span>全部7个&gt;</span>
  88. </div>
  89. <ul class="detail">
  90. <li onclick="">
  91. <img src="static/images/dgjj.png" alt="" />
  92. <a href="">独孤九贱</a>
  93. <span>9门课程</span>
  94. </li>
  95. <li onclick="">
  96. <img src="static/images/ynxj.png" alt="" />
  97. <a href="">独孤九贱</a>
  98. <span>9门课程</span>
  99. </li>
  100. <li onclick="">
  101. <img src="static/images/tlbb.png" alt="" />
  102. <a href="">独孤九贱</a>
  103. <span>9门课程</span>
  104. </li>
  105. <li onclick="">
  106. <img src="static/images/phpkjkf.png" alt="" />
  107. <a href="">独孤九贱</a>
  108. <span>9门课程</span>
  109. </li>
  110. <li onclick="">
  111. <img src="static/images/phpksrm.png" alt="" />
  112. <a href="">独孤九贱</a>
  113. <span>9门课程</span>
  114. </li>
  115. </ul>
  116. </div>
  117. <div class="bottom-right">
  118. <div class="tel">
  119. <a href="" class="iconfont icon-weixin weixin"><h2>官方公众号</h2></a>
  120. <a href="" class="iconfont icon-qq qq"><h2>官方QQ群</h2></a>
  121. </div>
  122. </div>
  123. </div>
  124. </main>
  125. </body>
  126. </html>

css源码(部分)

  1. /* 右边菜单样式 */
  2. main .right {
  3. position: relative;
  4. padding-top: 30px;
  5. }
  6. /* 1.头像信息 */
  7. main .right .userinfo {
  8. display: grid;
  9. grid-template-columns: 70px 100px;
  10. grid-template-rows: 30px 30px 30px;
  11. place-content: center;
  12. place-items: center;
  13. position: relative;
  14. padding-bottom: 20px;
  15. border-bottom: 1px solid #bbb;
  16. }
  17. /* 头像 */
  18. main .right .userinfo a img {
  19. border-radius: 50%;
  20. width: 40px;
  21. }
  22. main .right .userinfo a {
  23. grid-area: 1 / 1 / span 2 / span 1;
  24. place-self: center end;
  25. }
  26. main .right .userinfo .name {
  27. font-size: 12px;
  28. place-self: end center;
  29. padding-right: 20px;
  30. font-weight: bolder;
  31. }
  32. main .right .userinfo .info {
  33. font-size: 12px;
  34. place-self: start center;
  35. padding-right: 20px;
  36. }
  37. main .right .userinfo .button {
  38. grid-column: 1 / 3;
  39. grid-row: 3 / 4;
  40. width: 130px;
  41. height: 30px;
  42. border:1px solid red;
  43. text-align: center;
  44. line-height: 30px;
  45. font-size: 13px;
  46. background-color: red;
  47. border-radius: 20px;
  48. }
  49. main .right .userinfo .button a {
  50. color: white;
  51. }
  52. main .right .userinfo .info {
  53. grid-column: 2 / 3;
  54. grid-row: 2 / 3;
  55. font-weight: lighter;
  56. }
  57. main .right .tab {
  58. display: grid;
  59. grid-template-columns: 60px 90px;
  60. grid-template-rows: repeat(6,35px);
  61. grid-auto-flow: column;
  62. place-content: center;
  63. place-items: center start;
  64. text-align: center;
  65. font-size: smaller;
  66. position: relative;
  67. top: 20px;
  68. }
  69. main .right .tab li:nth-last-of-type(n+7) {
  70. font-weight: bolder;
  71. font-size: 14px;
  72. }
  73. main .right .tab li:nth-of-type(n+7) {
  74. font-size: 10px;
  75. }
  76. main .right .tab .content7 {
  77. place-self: center;
  78. background-color: red;
  79. }
  80. main .right .tab .content7 a {
  81. color: white;
  82. }
  83. main .right .tab a:hover {
  84. color: red;
  85. }
  86. /* 右边菜单底部 */
  87. main .navs .bottom-right .tel {
  88. display: flex;
  89. place-content: space-evenly;
  90. place-items: center;
  91. text-align: center;
  92. padding: 20px;
  93. }
  94. main .navs .bottom-right .tel h2 {
  95. font-size: 10px;
  96. }

实际效果:

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