博客列表 >Flex布局实现PHP中文网移动端-20191227作业

Flex布局实现PHP中文网移动端-20191227作业

涡流
涡流原创
2019年12月29日 16:20:48485浏览

html代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <!--引入阿里字体图标库的css-->
  6. <link rel="stylesheet" href="../iconfont/iconfont.css">
  7. <link rel="stylesheet" href="mobile.css">
  8. <title>移动端布局</title>
  9. </head>
  10. <body>
  11. <!-- 页眉,使用字体图标代替右上角图片 -->
  12. <header>
  13. <img src="img/user.jpg" alt="">
  14. <img src="img/logo.png" alt="">
  15. <i class="iconfont icon-icon_shezhi"></i>
  16. </header>
  17. <!-- 主体,有三部分内容 -->
  18. <main>
  19. <!-- 第一段:轮播图和课程图标 -->
  20. <div class="nav">
  21. <img src="img/nav.jpg" alt="">
  22. <div class="subject">
  23. <a href=""><i class="iconfont icon-html"></i>HTML/CSS</a>
  24. <a href=""><i class="iconfont icon-js"></i>javaScript</a>
  25. <a href=""><i class="iconfont icon-icon_shezhi"></i>服务端</a>
  26. <a href=""><i class="iconfont icon-fenzuguanli"></i>数据库</a>
  27. <a href=""><i class="iconfont icon-APPkaifa"></i>移动端</a>
  28. <a href=""><i class="iconfont icon-icon_bangzhuwendang"></i>手册</a>
  29. <a href=""><i class="iconfont icon-bianji"></i>工具</a>
  30. <a href=""><i class="iconfont icon-yunhang"></i>直播</a>
  31. </div>
  32. </div>
  33. <h3>推荐课程</h3>
  34. <!-- 推荐课程两张图片 -->
  35. <div class="class">
  36. <img src="img/class.jpg" alt="">
  37. <img src="img/class.jpg" alt="">
  38. </div>
  39. <h3>最新更新</h3>
  40. <div class="content">
  41. <img src="img/nav.jpg" alt="">
  42. <div class="detail">
  43. <span>PHP开发免费公益直播课</span>
  44. <span>主讲:php中文网-朱老师(Peter Zhu),时间:2019年12月18日起</span>
  45. <div class="status">
  46. <span>初级</span>
  47. <span>3671次播放</span>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="content">
  52. <img src="img/nav.jpg" alt="">
  53. <div class="detail">
  54. <span>PHP开发免费公益直播课</span>
  55. <span>主讲:php中文网-朱老师(Peter Zhu),时间:2019年12月18日起</span>
  56. <div class="status">
  57. <span>初级</span>
  58. <span>3671次播放</span>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="content">
  63. <img src="img/nav.jpg" alt="">
  64. <div class="detail">
  65. <span>PHP开发免费公益直播课</span>
  66. <span>主讲:php中文网-朱老师(Peter Zhu),时间:2019年12月18日起</span>
  67. <div class="status">
  68. <span>初级</span>
  69. <span>3671次播放</span>
  70. </div>
  71. </div>
  72. </div>
  73. <div class="content">
  74. <img src="img/nav.jpg" alt="">
  75. <div class="detail">
  76. <span>PHP开发免费公益直播课</span>
  77. <span>主讲:php中文网-朱老师(Peter Zhu),时间:2019年12月18日起</span>
  78. <div class="status">
  79. <span>初级</span>
  80. <span>3671次播放</span>
  81. </div>
  82. </div>
  83. </div>
  84. <h3>最新文章</h3>
  85. <div class="article">
  86. <div class="detail">
  87. <span>linux的终端是什么?</span>
  88. <span>发布时间:2019-12-17</span>
  89. </div>
  90. <img src="img/nav.jpg" alt="">
  91. </div>
  92. <div class="article">
  93. <div class="detail">
  94. <span>linux的终端是什么?</span>
  95. <span>发布时间:2019-12-17</span>
  96. </div>
  97. <img src="img/nav.jpg" alt="">
  98. </div>
  99. <div class="article">
  100. <div class="detail">
  101. <span>linux的终端是什么?</span>
  102. <span>发布时间:2019-12-17</span>
  103. </div>
  104. <img src="img/nav.jpg" alt="">
  105. </div>
  106. </main>
  107. <!-- 页脚,采用字体图标和文字 -->
  108. <footer>
  109. <span><i class="iconfont icon-daohangshouye"></i>首页</span>
  110. <span><i class="iconfont icon-yunhang"></i>视频</span>
  111. <span><i class="iconfont icon-quanxianshenpi"></i>社区</span>
  112. <span><i class="iconfont icon-huiyuan2"></i>我的</span>
  113. </footer>
  114. </body>
  115. </html>

CSS代码

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. /* outline: 1px solid green; */
  5. }
  6. a {
  7. text-decoration: none;
  8. color: grey;
  9. }
  10. img {
  11. width: 100%;
  12. }
  13. /* body设置为flex,垂直排列不换行 */
  14. body {
  15. /* min-width: 360px; */
  16. /* max-width: 768px; */
  17. width: 100vw;
  18. height: 100vh;
  19. display: flex;
  20. flex-flow: column nowrap;
  21. }
  22. /* 页眉样式,黑色背景,FLEX,水平排列不换行,两端对齐,垂直居中 */
  23. header {
  24. height: 40px;
  25. background-color: black;
  26. display: flex;
  27. justify-content: space-between;
  28. align-items: center;
  29. }
  30. header > img:first-of-type {
  31. width: 30px;
  32. height: 30px;
  33. border-radius: 50%;
  34. margin: 0 0 0 5px;
  35. }
  36. header > img:last-of-type {
  37. width: 94px;
  38. }
  39. header > i {
  40. margin: 0 5px 0 0;
  41. }
  42. header > .iconfont {
  43. font-size: 2rem;
  44. color: white;
  45. }
  46. /* 主体,水平方向无滚动条,垂直方向自动滚动,水平居中FLEX,垂直排列不换行 */
  47. main {
  48. overflow-y: auto;
  49. overflow-x: hidden;
  50. display: flex;
  51. flex-flow: column nowrap;
  52. margin: 0 auto;
  53. }
  54. /* NAV包含轮播图和图标链接,FLEX,垂直不换行 */
  55. main > .nav {
  56. display: flex;
  57. flex-flow: column nowrap;
  58. }
  59. main > .nav > img {
  60. height: 120px;
  61. }
  62. /* 图标链接8个,FLEX水平换行,每个图标宽21VW,保持一行4个,两端对齐 */
  63. main > .nav > .subject {
  64. width: 100vw;
  65. display: flex;
  66. flex-flow: row wrap;
  67. justify-content: space-around;
  68. }
  69. main > .nav > .subject > a {
  70. display: flex;
  71. flex-flow: column nowrap;
  72. width: 21vw;
  73. height: 8vh;
  74. justify-content: center;
  75. text-align: center;
  76. }
  77. main > .nav > .subject > a > .iconfont {
  78. font-size: 2rem;
  79. text-align: center;
  80. }
  81. main > h3 {
  82. margin: 15px 0 5px 10px;
  83. }
  84. /* 推荐课程两张图片,FLEX水平不换行,分散对齐 */
  85. main > .class {
  86. display: flex;
  87. flex-flow: row nowrap;
  88. justify-content: space-around;
  89. }
  90. main > .class > img {
  91. width: 45vw;
  92. border-radius: 3px;
  93. }
  94. main > .content {
  95. display: flex;
  96. flex-flow: row nowrap;
  97. margin: 5px;
  98. }
  99. main > .content > img {
  100. width: 30vw;
  101. margin: 0 5px;
  102. border-radius: 3px;
  103. }
  104. main > .content > .detail {
  105. display: flex;
  106. flex-flow: column nowrap;
  107. color: #666666;
  108. }
  109. main > .content > .detail > .status {
  110. display: flex;
  111. flex-flow: row nowrap;
  112. justify-content: space-between;
  113. }
  114. main > .content > .detail span:nth-child(2) {
  115. font-size: 0.8rem;
  116. }
  117. main > .content > .detail > .status span:first-of-type {
  118. background-color: #cccccc;
  119. padding: 3px 5px;
  120. border-radius: 8px;
  121. }
  122. main > .article {
  123. display: flex;
  124. justify-content: space-between;
  125. margin: 5px;
  126. }
  127. main > .article > .detail {
  128. display: flex;
  129. flex-direction: column;
  130. flex-grow: auto;
  131. margin: 0 5px;
  132. }
  133. main > .article > .detail > span:last-of-type {
  134. font-size: 0.8rem;
  135. }
  136. main > .article > img {
  137. width: 20vw;
  138. margin: 0 5px;
  139. border-radius: 3px;
  140. }
  141. footer {
  142. /* position: fixed; */
  143. display: flex;
  144. height: 50px;
  145. justify-content: space-between;
  146. background-color: #cccccc;
  147. }
  148. footer span {
  149. display: flex;
  150. flex-flow: column nowrap;
  151. margin: 0 20px;
  152. }
  153. footer > span > .iconfont {
  154. text-align: center;
  155. }
  156. footer > span:first-of-type {
  157. color: red;
  158. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议