博客列表 >flex实战移动端页面布局—Php第十期线上班

flex实战移动端页面布局—Php第十期线上班

迫
原创
2020年01月14日 11:37:25460浏览

2019.12.27作业

移动端m.php.cn布局(flex)实现

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>1227作业</title>
  6. <link rel="stylesheet" href="../static/font/iconfont.css">
  7. <link rel="stylesheet" href="PC-PAGE.css">
  8. </head>
  9. <body>
  10. <header>
  11. <a href=""><i class="iconfont icon-huiyuan2"></i>登录</a>
  12. <img src="../static/images/logo.png" alt="">
  13. <a href=""><i class="iconfont"></i></a>
  14. </header>
  15. <main>
  16. <header><img src="../static/images/ad/ad2.jpg" alt="" height="100%"></header>
  17. <nav>
  18. <a href=""><img src="../static/images/01.png" alt="" height="80" width="80"><span>PS</span></a>
  19. <a href=""><img src="../static/images/02.png" alt="" height="80" width="80"><span>C++</span></a>
  20. <a href=""><img src="../static/images/03.png" alt="" height="80" width="80"><span>ANDROID</span></a>
  21. <a href=""><img src="../static/images/04.png" alt="" height="80" width="80"><span>JAVA</span></a>
  22. <a href=""><img src="../static/images/01.png" alt="" height="80" width="80"><span>PS</span></a>
  23. <a href=""><img src="../static/images/02.png" alt="" height="80" width="80"><span>C++</span></a>
  24. <a href=""><img src="../static/images/03.png" alt="" height="80" width="80"><span>ANDROID</span></a>
  25. <a href=""><img src="../static/images/04.png" alt="" height="80" width="80"><span>JAVA</span></a>
  26. </nav>
  27. <section>
  28. <h2>最近消息</h2>
  29. <article>
  30. <section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
  31. <section>2020年1月十大最新热门笔记本电脑</section>
  32. </article>
  33. <article>
  34. <section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
  35. <section>2020年1月十大最新热门笔记本电脑</section>
  36. </article>
  37. <article>
  38. <section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
  39. <section>2020年1月十大最新热门笔记本电脑</section>
  40. </article>
  41. <article>
  42. <section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
  43. <section>2020年1月十大最新热门笔记本电脑</section>
  44. </article>
  45. <article>
  46. <section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
  47. <section>2020年1月十大最新热门笔记本电脑</section>
  48. </article>
  49. <article>
  50. <section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
  51. <section>2020年1月十大最新热门笔记本电脑</section>
  52. </article>
  53. <article>
  54. <section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
  55. <section>2020年1月十大最新热门笔记本电脑</section>
  56. </article>
  57. <article>
  58. <section><img src="../static/images/shop/9.jpg" alt="" width="100%"></section>
  59. <section>2020年1月十大最新热门笔记本电脑</section>
  60. </article>
  61. </section>
  62. </main>
  63. <footer>
  64. <a href=""><i class="iconfont"></i></a>
  65. <a href=""><i class="iconfont"></i></a>
  66. <a href=""><i class="iconfont"></i></a>
  67. </footer>
  68. </body>
  69. </html>

css样式

  1. *{
  2. margin: 0;
  3. /*padding: 0;outline: 1px dashed;*/
  4. }
  5. body{
  6. display: flex;
  7. flex-direction: column;
  8. min-width: 360px;
  9. height: 100vh;
  10. width: 100vw;
  11. }
  12. body > header {
  13. display: flex;
  14. flex-direction: row;
  15. height: 8vh;
  16. width: 100vw;
  17. min-width: 360px;
  18. background-color: black;
  19. box-sizing: border-box;
  20. }
  21. body > header > a {
  22. text-decoration: none;
  23. font-size: 16px;
  24. color: white;
  25. flex: 1;
  26. margin: auto;
  27. }
  28. body > header > a > i {
  29. margin-left: 3px;
  30. margin-right: 3px;
  31. }
  32. body > header > a:last-of-type {
  33. display: flex;
  34. justify-content: flex-end;
  35. margin-right: 3px;
  36. }
  37. body > main {
  38. flex-grow: 1;
  39. overflow: auto;
  40. display: flex;
  41. flex-direction: column;
  42. }
  43. body > main > header{
  44. display: flex;
  45. flex-direction: column;
  46. }
  47. body > main > header > img {
  48. align-self: center;
  49. padding: 1px;
  50. }
  51. body > main > nav {
  52. align-self: center;
  53. display: flex;
  54. flex-wrap: wrap;
  55. flex-direction: row;
  56. width: 400px;
  57. }
  58. body > main > nav > a {
  59. display: flex;
  60. flex-direction: column;
  61. text-decoration: none;
  62. flex-basis: 80px;
  63. flex-grow: 1;
  64. }
  65. body > main > nav > a > img{
  66. align-self: center;
  67. }
  68. body > main > nav > a > span{
  69. font-size: 20px;
  70. color: black;
  71. align-self: center;
  72. }
  73. body > main > section {
  74. /*display: flex;*/
  75. border-top: 1px lightgray solid;
  76. margin: 5px;
  77. }
  78. body > main > section > article{
  79. background-color: lightcyan;
  80. box-shadow: 0 0 2px #888888;
  81. margin: 1vh 0;
  82. display: flex;
  83. }
  84. body > main > section > article > section:first-of-type {
  85. width: 24vw;
  86. height: 10vh;
  87. display: flex;
  88. }
  89. body > main > section > article > section:first-of-type>img{
  90. align-self: center;
  91. margin-left: 1vw;
  92. height: 8vh;
  93. }
  94. body > main > section > article > section:last-of-type {
  95. flex: 1;
  96. background-color: lightcyan;
  97. margin: 0 1vw;
  98. box-shadow: 0 0 2px lightgray;
  99. align-self: center;
  100. padding-left: 30px;
  101. }
  102. body > footer {
  103. display: flex;
  104. flex-direction: row;
  105. height: 8vh;
  106. width: 100vw;
  107. min-width: 360px;
  108. background-color: black;
  109. box-sizing: border-box;
  110. justify-content: space-around;
  111. }
  112. body > footer > a{
  113. color: white;
  114. align-self: center;
  115. text-decoration: none;
  116. }

总结,移动端页面的特点是头尾固定,中间主体滑动,在设计页面的时候,要将整个页面显示高度先设定好body{height:100vh;},再将头尾显示高度设定好,中间主体部分添加滑动轴main{overflow: auto;},一次完成基础的页面布置。注意两个单位:vh(显示高度),vw(显示宽度),二者都是百分比单位,是当前页面百分比。

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议