博客列表 >grid+flex布局实例

grid+flex布局实例

P粉116103988
P粉116103988原创
2022年07月21日 22:06:36285浏览

grid+flex布局仿 PHP 页头

效果图如下:

代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  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>仿PHP</title>
  8. <link rel="stylesheet" href="./font/iconfont.css">
  9. <link rel="stylesheet" href="/0713/static/css/reset.css">
  10. <style>
  11. .header {
  12. height: 130px;
  13. }
  14. .header .top{
  15. width: 100VW;
  16. height: 40px;
  17. background-color: #444546;
  18. }
  19. .header .top .content{
  20. /* 定义居中: 内容区需要有宽度 */
  21. width: 1200px;
  22. margin: auto;
  23. display: grid;
  24. grid-template-columns: 400px 100px;
  25. grid-auto-rows: 40px;
  26. place-content: space-between space-between;
  27. place-items: center start;
  28. }
  29. .header .top .content .title a{
  30. color: #fff;
  31. font-weight: lighter;
  32. }
  33. .header .top .content .top-r{
  34. display: flex;
  35. color: #fff;
  36. }
  37. .header .top .content .top-r span{
  38. padding: 0 10px;
  39. }
  40. .header .top .content .top-r .icon-lingdang{
  41. font-size: 22px;
  42. }
  43. .header .top .content .top-r img{
  44. width: 80%;
  45. border-radius: 50%;
  46. }
  47. .header .navs{
  48. width: 100vw;
  49. background-color: #fff;
  50. height: 90px;
  51. box-shadow: 0 5px 10px rgba(0,0,0,0.1);
  52. }
  53. .header .navs .content{
  54. width: 1200px;
  55. margin: auto;
  56. display: grid;
  57. /* 1fr=auto */
  58. grid-template-columns: 140px 1fr 200px;
  59. /* 格子间距 */
  60. gap: 10px;
  61. grid-auto-rows: 90px;
  62. place-items: center start;
  63. }
  64. .header .navs .content img{
  65. width: 100%;
  66. }
  67. .header .navs .content .menu{
  68. display: flex;
  69. }
  70. .header .navs .content .menu a{
  71. padding: 0 10px;
  72. }
  73. .header .navs .content .menu a:hover,
  74. .header .navs .content .menu a.active{
  75. color: red;
  76. font-weight: bold;
  77. }
  78. .header .navs .content .right{
  79. display: flex;
  80. }
  81. .header .navs .content .right input[type="search"]{
  82. width: 200px;
  83. height: 36px;
  84. border-radius: 20px;
  85. border: none;
  86. outline: none;
  87. background-color: #eee;
  88. padding-left: 10px;
  89. }
  90. .header .navs .content .right .icon-sousuo{
  91. font-size: 22px;
  92. color: #ccc;
  93. position: relative;
  94. left: -30px;
  95. top:5px
  96. }
  97. .header .navs .content .right .icon-sousuo:hover{
  98. color: red;
  99. cursor: pointer;
  100. }
  101. </style>
  102. </head>
  103. <body>
  104. <!-- 页眉 -->
  105. <div class="header">
  106. <!-- 头部 -->
  107. <div class="top">
  108. <div class="content">
  109. <div class="title"> <a href="">PHP中文网-程序员梦开始的地方!</a></div>
  110. <div class="top-r">
  111. <span class="iconfont icon-lingdang"></span>
  112. <span class="iconfont"><a href=""><img src="/0713/static/images/user-pic.jpeg" alt=""></a></span>
  113. </div>
  114. </div>
  115. </div>
  116. <!-- 导航 -->
  117. <div class="navs">
  118. <div class="content">
  119. <a href=""><img src="../0713/static/images/logo.png" alt=""></a>
  120. <nav class="menu">
  121. <a href="" class="active">首页</a>
  122. <a href="">视频教程</a>
  123. <a href="">学习路径</a>
  124. <a href="">PHP培训</a>
  125. <a href="">资源下载</a>
  126. <a href="">技术文章</a>
  127. </nav>
  128. <div class="right">
  129. <input type="search" placeholder="请输入关键字">
  130. <a><span class="iconfont icon-sousuo"></span></a>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </body>
  136. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议