Blogger Information
Blog 13
fans 0
comment 0
visits 8416
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
grid实战 快速实现php.cn首页主要组件
一米互联
Original
656 people have browsed it

快速实现php.cn首页主要组件的布局

css代码:
  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. li{
  7. list-style: none;
  8. }
  9. a{
  10. color: #444444;
  11. text-decoration: none;
  12. }
  13. header{
  14. height: 10vh;
  15. background: rgb(50, 51, 51);
  16. margin-bottom: 30px;
  17. color:white;
  18. }
  19. footer{
  20. height: 125px;
  21. color:white;
  22. background: rgb(50, 51, 51) ;
  23. margin-top: 34px;
  24. }
  25. .main-top{
  26. min-height: 410px;
  27. width: 1200px;
  28. margin-bottom: 30px;
  29. display: grid;
  30. grid-template-columns: 216px 1fr;
  31. grid-template-rows: 60px 1fr 120px;
  32. margin: auto;
  33. }
  34. /* 左侧导航区 */
  35. .main-top>nav.menus{
  36. grid-area: span 3; /*跨越三行*/
  37. background: lightskyblue;
  38. border-radius: 10px 0 0 10px;
  39. text-align: center;
  40. }
  41. .main-top>.menus a{
  42. color: #616161;
  43. font-size: 12px;
  44. }
  45. .main-top .menus a span{
  46. float: right;
  47. padding-right: 15px;
  48. }
  49. .main-top .menus li{
  50. height: 60px;
  51. text-align: left;
  52. line-height: 60px;
  53. padding-left: 15px;
  54. border: 1px dotted #d8d8d8;
  55. }
  56. /* 顶部导航区 */
  57. .main-top>ul.navs{
  58. background: lightcyan;
  59. display: grid;
  60. grid-template-columns: repeat(8,83px) 1fr;
  61. place-items: center;
  62. border-radius: 0 10px 0 0;
  63. font-size: 12px;
  64. }
  65. .main-top>ul.navs li{
  66. position: relative;
  67. }
  68. .main-top>ul.navs li img{
  69. position: absolute;
  70. top: -10px;
  71. right: -21px;
  72. }
  73. .main-top>ul.navs>li:last-of-type{
  74. place-self:center start;
  75. padding-left: 30px;
  76. }
  77. .main-top .navs input{
  78. width:230px;
  79. height: 40px;
  80. background: #f1f1f1;
  81. border: none;
  82. padding-left: 20px;
  83. }
  84. .main-top>.slider{
  85. height: 300px;
  86. background: slategrey;
  87. }
  88. /* 课程推荐图 */
  89. .main-top>ul.course{
  90. background: rgb(253, 203, 111);
  91. display: grid;
  92. grid-template-columns: repeat(4,1fr);
  93. gap: 10px;
  94. padding: 10px;
  95. border-radius: 0 0 10px 0;
  96. place-items: center center;
  97. }
  98. .main-top>ul.course>li{
  99. background: magenta;
  100. cursor: pointer;
  101. height: 90px;
  102. }
  103. /* PHP入门精品课 */
  104. .main-course{
  105. width: 1200px;
  106. height: 646px;
  107. padding: 15px;
  108. background: lightskyblue;
  109. margin: 30px auto;
  110. display: grid;
  111. grid-template-rows: 50px 1fr;
  112. gap: 10px;
  113. border-radius: 10px;
  114. }
  115. .main-course h3{
  116. background:white;
  117. text-align: center;
  118. margin-bottom: 30px;
  119. height: 50px;
  120. line-height: 50px;
  121. }
  122. .main-course .course-list{
  123. display: grid;
  124. gap: 20px;
  125. grid-template-columns:repeat(5,1fr);
  126. grid-template-rows: repeat(3,1fr);
  127. }
  128. .main-course .course-list>*{
  129. background:white;
  130. border-radius: 10px;
  131. }
  132. .main-course .course-list>li:first-of-type{
  133. grid-area: span 2;
  134. }
  135. .main-course .course-list>li img{
  136. width:100%;
  137. }
  138. .main-course .course-list li span{
  139. display: inline-block;
  140. padding: 5px 15px 0;
  141. font-size: 13px;
  142. }
HTML代码:
  1. <header>页眉</header>
  2. <div class="main-top">
  3. <!-- 侧边菜单 -->
  4. <nav class="menus">
  5. <ul>
  6. <li><a href="">PHP开发<span>&gt;</span></a></li>
  7. <li><a href="">前端开发<span>&gt;</span></a></li>
  8. <li><a href="">服务端开发<span>&gt;</span></a></li>
  9. <li><a href="">移动开发<span>&gt;</span></a></li>
  10. <li><a href="">数据库<span>&gt;</span></a></li>
  11. <li><a href="">服务器运维&下载<span>&gt;</span></a></li>
  12. <li><a href="">在线工具箱<span>&gt;</span></a></li>
  13. <li><a href="">常用类库<span>&gt;</span></a></li>
  14. </ul>
  15. </nav>
  16. <!-- 顶部菜单 -->
  17. <ul class="navs">
  18. <li><a href="">PHP头条</a><img src="img/1.png"/></li>
  19. <li><a href="">独孤九剑</a></li>
  20. <li><a href="">学习路线</a></li>
  21. <li><a href="">在线工具</a></li>
  22. <li><a href="">趣味课堂</a></li>
  23. <li><a href="">社区回答</a></li>
  24. <li><a href="">课程直播</a></li>
  25. <li><a href="">你猜你猜</a></li>
  26. <li><input type="text" placeholder="输入关键字搜索..."></li>
  27. </ul>
  28. <div class="slider"><img src="img/2.jpg" width="100%" alt="轮播图"/></div>
  29. <!-- 底部的课程推荐 -->
  30. <ul class="course">
  31. <li><a href=""><img src="img/3.jpg" width="100%" alt=""></a></li>
  32. <li><a href=""><img src="img/4.png" width="100%" alt=""></a></li>
  33. <li><a href=""><img src="img/5.jpg" width="100%" alt=""></a></li>
  34. <li><a href=""><img src="img/6.jpg" width="100%" alt=""></a></li>
  35. </ul>
  36. <!-- 课程列表区 -->
  37. <div class="main-course">
  38. <h3>&lt;\&gt;PHP入门精品课程&lt;\&gt;</h3>
  39. <ul class="course-list">
  40. <li><a href=""><img src="img/7.jpg" alt=""></a></li>
  41. <li>
  42. <a href="">
  43. <img src="img/8.png" height="124px" alt="">
  44. <span>初级:编程学习方法分享直播公益课</span>
  45. </a>
  46. </li>
  47. <li>
  48. <a href=""><img src="img/9.jpg" height="124px" alt="">
  49. <span>初级:编程学习方法分享直播公益课</span>
  50. </a>
  51. </li>
  52. <li>
  53. <a href=""><img src="img/10.jpg" height="124px" alt="">
  54. <span>初级:编程学习方法分享直播公益课</span>
  55. </a>
  56. </li>
  57. <li><a href=""><img src="img/11.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  58. <li><a href=""><img src="img/12.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  59. <li><a href=""><img src="img/13.jpeg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  60. <li><a href=""><img src="img/14.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  61. <li><a href=""><img src="img/15.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  62. <li><a href=""><img src="img/16.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  63. <li><a href=""><img src="img/17.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  64. <li><a href=""><img src="img/18.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  65. <li><a href=""><img src="img/19.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  66. <li><a href=""><img src="img/20.jpg" height="124px" alt=""><span>初级:编程学习方法分享直播公益课</span></a></li>
  67. </ul>
  68. </div>
  69. </div>
  70. <footer>页脚</footer>

grid的媒体查询

css代码:
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body {
  7. background-color: rgb(250, 232, 66);
  8. }
  9. a {
  10. text-decoration: none;
  11. color:black;
  12. padding-top: 10px;
  13. }
  14. h1 {
  15. color: rgb(77, 29, 250);
  16. text-align: center;
  17. font-weight: bolder;
  18. margin-top: 10px;
  19. }
  20. img {
  21. width: 100%;
  22. }
  23. .cat-pic{
  24. min-width: 100vw;
  25. min-height: 100vh;
  26. padding: 30px;
  27. display: grid;
  28. gap: 1.5em;
  29. /* 自动填充,可以实现媒体查询的效果 */
  30. grid-template-columns: repeat(auto-fit, minmax(15em, 1fr));
  31. grid-template-rows: repeat(auto-fit, minmax(13em, 70%));
  32. }
  33. .cat-pic .cat {
  34. background-color: #eee;
  35. padding: 1em;
  36. border-radius: 15px; /*圆角*/
  37. display: grid;
  38. place-items: center; /*项目对齐方式*/
  39. }
  40. .cat-pic .cat:hover {
  41. background:cyan;
  42. cursor: pointer;
  43. transition: 0.5s; /*延时*/
  44. }
HTML代码:
  1. <h1>萌宠相册</h1>
  2. <div class="cat-pic">
  3. <div class="cat">
  4. <img src="img/cat.jpg" alt="">
  5. <a href="">萌宠1</a>
  6. </div>
  7. <div class="cat">
  8. <img src="img/cat.jpg" alt="">
  9. <a href="">萌宠2</a>
  10. </div>
  11. <div class="cat">
  12. <img src="img/cat.jpg" alt="">
  13. <a href="">萌宠3</a>
  14. </div>
  15. <div class="cat">
  16. <img src="img/cat.jpg" alt="">
  17. <a href="">萌宠4</a>
  18. </div>
  19. <div class="cat">
  20. <img src="img/cat.jpg" alt="">
  21. <a href="">萌宠5</a>
  22. </div>
  23. <div class="cat">
  24. <img src="img/cat.jpg" alt="">
  25. <a href="">萌宠6</a>
  26. </div>
  27. <div class="cat">
  28. <img src="img/cat.jpg" alt="">
  29. <a href="">萌宠7</a>
  30. </div>
  31. <div class="cat">
  32. <img src="img/cat.jpg" alt="">
  33. <a href="">萌宠8</a>
  34. </div>
  35. <div class="cat">
  36. <img src="img/cat.jpg" alt="">
  37. <a href="">萌宠9</a>
  38. </div>
  39. </div>


grid的媒体查询与专业的媒体查询有什么区别:
1.grid媒体查询主要通过auto-fit属性自动填充来实现类似媒体查询功能
2.专业的媒体查询由一个可选的媒体类型和零个或多个使用媒体功能的限制了样式表范围的表达式组成。
语法:@media 媒体类型 and (媒体特性) { }

Correcting teacher:天蓬老师天蓬老师

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