亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 31
粉絲 2
評論 0
訪問量 34481
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
flex實例:PC端和移動端布局
霏夢
原創(chuàng)
1172人瀏覽過

— 作者:霏夢

pc端通用布局解決方案flex

  • html代碼如下:
    1. <div class="box">
    2. <div class="header">
    3. <a href="#">LOGO</a>
    4. <a href="">產品</a>
    5. <a href="">定價</a>
    6. <a href="">解決方案</a>
    7. <a href="">支持</a>
    8. <a href="">下載</a>
    9. <a href="">免費使用</a>
    10. </div>
    11. <div class="container">
    12. <div class="aside">我在左邊</div>
    13. <div class="main">我是內容區(qū)</div>
    14. <div class="aside">我在右邊</div>
    15. </div>
    16. <div class="footer">
    17. <p><a href="">使用條款</a> <a href="">隱私政策</&a></p>
    18. <p>霏夢公司 Copyright ? 2020 京ICP備080000000號</p>
    19. </div>
    20. </div>
  • CSS代碼如下:

    1. <style>
    2. /* 初始化 */
    3. * {
    4. margin: 0;
    5. padding: 0;
    6. box-sizing: border-box;
    7. }
    8. /* body轉為flex */
    9. body{
    10. min-width: 800px;
    11. display: flex;
    12. /* 垂直不換行 */
    13. flex-flow: row nowrap;
    14. justify-content: center;
    15. }
    16. /* box轉為flex */
    17. .box {
    18. min-width: 800px;
    19. display: flex;
    20. /* 垂直不換行 */
    21. flex-flow: column nowrap;
    22. }
    23. .header,
    24. .footer{
    25. height: 50px;
    26. border: 1px solid black;
    27. }
    28. .header{
    29. display: flex;
    30. /* 交叉軸上垂直居中顯示 */
    31. align-items: center;
    32. }
    33. .header > a {
    34. color: coral;
    35. text-decoration: none;
    36. flex: 0 1 100px;
    37. /* 文本居中 */
    38. text-align: center;
    39. }
    40. .header > a:first-of-type{
    41. margin-right: 50px;
    42. }
    43. .header > a:last-of-type{
    44. /* 免費使用 往最右 */
    45. margin-left: auto;
    46. }
    47. /* 鼠標懸停時忽略logo */
    48. .header >a:hover:not(:first-of-type){
    49. background-color: chartreuse;
    50. color:darkblue;
    51. }
    52. .container {
    53. display: flex;
    54. min-height: 300px;
    55. margin: 10px auto;
    56. justify-content: center;
    57. text-align: center;
    58. }
    59. .container > .aside,
    60. .container>.main{
    61. border: 1px solid darkorange;
    62. padding: 10px;
    63. }
    64. .container >.aside{
    65. flex:0 0 200px;
    66. }
    67. .container >.main{
    68. flex: 0 0 380px;
    69. margin: 0 10px;
    70. }
    71. .footer{
    72. display: flex;
    73. /* 垂直方向不換行*/
    74. flex-flow: column nowrap;
    75. text-align: center;
    76. }
    77. .footer > p > a{
    78. text-decoration: none;
    79. }
    80. </style>
  • 如圖所示:
    flex

移動端布局方案

  • html代碼如下:

    1. <body>
    2. <!-- 頁眉 -->
    3. <header>
    4. <a href="">LOGO</a>
    5. <span class="iconfont">&#xe61f;</span>
    6. </header>
    7. <!-- 輪播區(qū)域 -->
    8. <div class="slider">
    9. <img src="static/images/banner.jpg" alt="" />
    10. </div>
    11. <!-- 主要導航區(qū)域 -->
    12. <div class="nav">
    13. <div>
    14. <a href=""><img src="static/images/link1.webp" alt="" /></a>
    15. <a href="">天貓超市</a>
    16. </div>
    17. <div>
    18. <a href=""><img src="static/images/link2.webp" alt="" /></a>
    19. <a href="">服裝百貨</a>
    20. </div>
    21. <div>
    22. <a href=""><img src="static/images/link3.webp" alt="" /></a>
    23. <a href="">數碼電器</a>
    24. </div>
    25. <div>
    26. <a href=""><img src="static/images/link1.webp" alt="" /></a>
    27. <a href="">圖書精品</a>
    28. </div>
    29. <div>
    30. <a href=""><img src="static/images/link1.webp" alt="" /></a>
    31. <a href="">天貓超市</a>
    32. </div>
    33. <div>
    34. <a href=""><img src="static/images/link2.webp" alt="" /></a>
    35. <a href="">服裝百貨</a>
    36. </div>
    37. <div>
    38. <a href=""><img src="static/images/link3.webp" alt="" /></a>
    39. <a href="">數碼電器</a>
    40. </div>
    41. <div>
    42. <a href=""><img src="static/images/link1.webp" alt="" /></a>
    43. <a href="">圖書精品</a>
    44. </div>
    45. </div>
    46. <h2>
    47. 商品熱銷區(qū)
    48. <span class="iconfont hot" style="color: coral;">&#xe60b;</span>
    49. </h2>
    50. <div class="goods-hot">
    51. <div class="goods-img">
    52. <a href=""><img src="static/images/goods1.jpg" alt="" /></a>
    53. <p>Apple iPhone 11 128G</p>
    54. <div>
    55. <span>6299&nbsp;元</span>
    56. <span class="iconfont hot">&#xe602;</span>
    57. </div>
    58. </div>
    59. <div class="goods-img">
    60. <a href=""><img src="static/images/goods1.jpg" alt="" /></a>
    61. <p>Apple iPhone X 512G</p>
    62. <div>
    63. <span>8299&nbsp;元</span>
    64. <span class="iconfont hot">&#xe602;</span>
    65. </div>
    66. </div>
    67. <div class="goods-img">
    68. <a href=""><img src="static/images/goods2.jpg" alt="" /></a>
    69. <p>華為筆記本電腦</p>
    70. <div>
    71. <span>5699&nbsp;元</span>
    72. <span class="iconfont hot">&#xe602;</span>
    73. </div>
    74. </div>
    75. <div class="goods-img">
    76. <a href=""><img src="static/images/goods2.jpg" alt="" /></a>
    77. <p>小米筆記本電腦</p>
    78. <div>
    79. <span>3999&nbsp;元</span>
    80. <span class="iconfont hot">&#xe602;</span>
    81. </div>
    82. </div>
    83. <div class="goods-img">
    84. <a href=""><img src="static/images/goods2.jpg" alt="" /></a>
    85. <p>聯想筆記本電腦</p>
    86. <div>
    87. <span>4399&nbsp;元</span>
    88. <span class="iconfont hot">&#xe602;</span>
    89. </div>
    90. </div>
    91. </div>
    92. <!-- 商品列表 -->
    93. <h2 class="title">
    94. 商品列表
    95. <span class="iconfont hot" style="color: tomato;">&#xe64b;</span>
    96. </h2>
    97. <div class="goods-list">
    98. <div class="goods-desc">
    99. <a href=""><img src="static/images/goods4.jpg" alt="" /></a>
    100. <a href=""
    101. >[白條24期免息]Apple蘋果iPhone 11 手機 128G 全網通, 免費領取500元話費,
    102. 今天17:00下單,明晨12:00之前送達,7天無理由退貨,官方提供售后,測試的</a
    103. >
    104. </div>
    105. <div class="goods-desc">
    106. <a href=""><img src="static/images/goods3.jpg" alt="" /></a>
    107. <a href=""
    108. >西門子泳衣機 免費領取500元話費,
    109. 今天17:00下單,明晨12:00之前送達,7天無理由退貨,官方提供售后,測試的</a
    110. >
    111. </div>
    112. <div class="goods-desc">
    113. <a href=""><img src="static/images/goods5.png" alt="" /></a>
    114. <a href=""
    115. >這是一部全屏手機,價格只要1元,顏色很多,免費3年維修更換,快遞免費,上門更換</a
    116. >
    117. </div>
    118. <div class="goods-desc">
    119. <a href=""><img src="static/images/goods2.jpg" alt="" /></a>
    120. <a href=""
    121. >ROG冰銳2 15.6英寸240Hz電競屏高色域輕薄便攜游戲本筆記本電腦(R9-4900HS
    122. 8核7nm 16G 1TSSD RTX2060MaxQ</a
    123. >
    124. </div>
    125. </div>
    126. <!-- 頁腳 -->
    127. <footer>
    128. <a href="">
    129. <span class="iconfont hot">&#xe60c;</span>
    130. <span>首頁</span>
    131. </a>
    132. <a href="">
    133. <span class="iconfont hot">&#xe60c;</span>
    134. <span>分類</span>
    135. </a>
    136. <a href="">
    137. <span class="iconfont hot">&#xe60c;</span>
    138. <span>購物車</span>
    139. </a>
    140. <a href="">
    141. <span class="iconfont hot">&#xe60c;</span>
    142. <span>未登錄</span>
    143. </a>
    144. </footer>
    145. </body>
  • css代碼如下 :

    1. <style>
    2. /* 初始化 */
    3. * {
    4. margin: 0;
    5. padding: 0;
    6. box-sizing: border-box;
    7. }
    8. a {
    9. text-decoration: none;
    10. color: grey;
    11. }
    12. html {
    13. /* 可視區(qū)域的寬和高 */
    14. width: 100vw;
    15. height: 100vh;
    16. font-size: 14px;
    17. /* font-family:Arial, Helvetica, sans-serif; */
    18. color: grey;
    19. }
    20. body {
    21. min-width: 360px;
    22. background-color: white;
    23. display: flex;
    24. flex-flow: column nowrap;
    25. }
    26. header {
    27. color: white;
    28. background-color: #333;
    29. height: 30px;
    30. display: flex;
    31. justify-content: space-between;
    32. align-items: center;
    33. position: fixed;
    34. width: 100vw;
    35. padding: 0 10px;
    36. }
    37. .slider {
    38. height: 180px;
    39. }
    40. .slider > img {
    41. height: 100%;
    42. }
    43. .nav {
    44. height: 200px;
    45. margin-bottom: 10px;
    46. display: flex;
    47. /* 轉為多行容器 */
    48. flex-flow: row wrap;
    49. align-content: space-around;
    50. }
    51. .nav > div {
    52. width: 25vw;
    53. display: flex;
    54. flex-flow: column nowrap;
    55. text-align: center;
    56. }
    57. .nav > div > a img {
    58. width: 50%;
    59. }
    60. .title {
    61. text-align: center;
    62. font-size: 1.6rem;
    63. font-weight: normal;
    64. }
    65. .goods-hot {
    66. border-top: 1px solid #cdcdcd;
    67. margin-top: 10px;
    68. font-size: 0.8rem;
    69. display: flex;
    70. /* 水平多行容器 */
    71. flex-flow: row wrap;
    72. }
    73. .goods-hot img {
    74. width: 100%;
    75. }
    76. .goods-hot > .goods-img {
    77. /* 內邊距并重置大小 */
    78. padding: 10px;
    79. box-sizing: border-box;
    80. /* 允許放大不允許縮小,否則項目不會換行,多行容器失效 */
    81. flex: 1 0 30vw;
    82. /* 轉為flex */
    83. display: flex;
    84. /* 主軸垂直且不允許換行 */
    85. flex-flow: column nowrap;
    86. justify-content: center;
    87. }
    88. /* 轉flex,主軸上排列對齊方式 */
    89. .goods-hot > .goods-img > div {
    90. display: flex;
    91. /* 分散對齊 */
    92. justify-content: space-around;
    93. }
    94. .goods-list {
    95. padding: 10px;
    96. border: 1px solid #cdcdcd;
    97. margin-top: 10px;
    98. font-size: 14px;
    99. display: flex;
    100. /* 主軸必須是垂直 */
    101. flex-flow: column nowrap;
    102. }
    103. .goods-list > .goods-desc {
    104. display: flex;
    105. margin: 10px 0;
    106. }
    107. .goods-list > .goods-desc > a {
    108. padding: 10px 0;
    109. box-sizing: border-box;
    110. }
    111. /* 圖片全部適應項目空間 */
    112. .goods-list > .goods-desc > a > img {
    113. width: 100%;
    114. }
    115. .goods-list > .goods-desc > a:last-of-type:hover {
    116. color: seagreen;
    117. }
    118. footer {
    119. color: #666;
    120. height: 60px;
    121. background-color: #efefef;
    122. border-top: 1px solid #666;
    123. position: fixed;
    124. bottom: 0;
    125. width: 100vw;
    126. display: flex;
    127. justify-content: space-around;
    128. }
    129. footer > a {
    130. margin-top: 10px;
    131. display: flex;
    132. /* 垂直排列不換行 */
    133. flex-flow: column nowrap;
    134. /* 交叉軸項目居中顯示 */
    135. align-items: center;
    136. }
    137. footer a > span:first-of-type {
    138. font-size: 1.6rem;
    139. }
    140. .hot {
    141. /* 底部圖標的顏色 */
    142. color: coral;
    143. }
    144. </style>
  • 圖標樣式和圖片,請自行替換,參考阿里圖標,這里就不寫了
  • 效果圖
    flex移動端

- 總結

  1. 建議用firefox瀏覽器,并寫并看效果,并調試
  2. 要清楚flex的容器和項目,特別要知道主軸和交叉軸的顯示
  3. 要會阿里圖標的應用
  4. 需要注意的是:當時設置 flex 布局之后,子元素的 float、clear、vertical-align 的屬性將會失效
  5. 有下面六種屬性可以設置在容器上,它們分別是:
    • flex-direction
    • flex-wrap
    • flex-flow
    • justify-content
    • align-items
    • align-content
批改老師:天蓬老師天蓬老師

批改狀態(tài):合格

老師批語:看來是明白了
本博文版權歸博主所有,轉載請注明地址!如有侵權、違法,請聯系admin@php.cn舉報處理!
全部評論 文明上網理性發(fā)言,請遵守新聞評論服務協議
0條評論
作者最新博文
關于我們 免責申明 意見反饋 講師合作 廣告合作 最新更新
php中文網:公益在線php培訓,幫助PHP學習者快速成長!
關注服務號 技術交流群
PHP中文網訂閱號
每天精選資源文章推送
PHP中文網APP
隨時隨地碎片化學習
PHP中文網抖音號
發(fā)現有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號

  • 登錄PHP中文網,和優(yōu)秀的人一起學習!
    全站2000+教程免費學