博客列表 >flex布局

flex布局

BARRY
BARRY原创
2020年09月26日 00:25:26693浏览

flex pc端布局

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>flex三列布局</title>
  7. <style>
  8. /* 初始化 */
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. a {
  15. text-decoration: none;
  16. color: cornflowerblue;
  17. }
  18. body {
  19. display: flex;
  20. flex-flow: column nowrap;
  21. width: 1100px;
  22. margin: auto;
  23. }
  24. header,
  25. footer {
  26. height: 50px;
  27. border: 1px solid;
  28. }
  29. header {
  30. display: flex;
  31. /* justify-content: center; */
  32. align-items: center;
  33. }
  34. header > a {
  35. flex: 0 1 120px;
  36. text-align: center;
  37. }
  38. header > a:first-of-type {
  39. margin-right: 80px;
  40. }
  41. header > a:last-of-type {
  42. margin-left: auto;
  43. }
  44. header > a:hover:not(:first-of-type) {
  45. color: crimson;
  46. }
  47. /* 内容区布局 */
  48. .container {
  49. display: flex;
  50. min-height: 600px;
  51. justify-content: space-between;
  52. }
  53. .container > aside {
  54. flex: 0 0 200px;
  55. }
  56. .container > main {
  57. flex: 0 0 600px;
  58. }
  59. footer {
  60. display: flex;
  61. flex-flow: column nowrap;
  62. text-align: center;
  63. }
  64. aside {
  65. background-color: greenyellow;
  66. }
  67. main {
  68. background-color: khaki;
  69. }
  70. /* 媒体查询 */
  71. @media screen and (max-width: 900px) {
  72. aside:last-of-type {
  73. display: none;
  74. }
  75. .container > main {
  76. flex: auto;
  77. }
  78. }
  79. @media screen and (max-width: 650px) {
  80. footer,
  81. aside,
  82. header > a:not(:first-of-type) {
  83. display: none;
  84. }
  85. }
  86. </style>
  87. </head>
  88. <body>
  89. <header>
  90. <a href="">LOGO</a>
  91. <a href="">首页</a>
  92. <a href="">分类</a>
  93. <a href="">新闻</a>
  94. <a href="">产品</a>
  95. <a href="">登录</a>
  96. </header>
  97. <div class="container">
  98. <aside>左侧</aside>
  99. <main>内容区</main>
  100. <aside>右侧</aside>
  101. </div>
  102. <footer>
  103. <p>。。。。。。版权所有 &copy;苏cc 8888-9999</p>
  104. <p>地址:江苏省苏州市金枫路888号</p>
  105. </footer>
  106. </body>
  107. </html>

运行结果

移动端布局

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>移动端flex</title>
  7. <link rel="stylesheet" href="iconfont/iconfont.css" />
  8. <link rel="stylesheet" href="icon01.css" />
  9. <script src="iconfont/iconfont.js"></script>
  10. <style>
  11. * {
  12. margin: 0;
  13. padding: 0;
  14. }
  15. a {
  16. text-decoration: none;
  17. color: #666;
  18. }
  19. html {
  20. width: 100vw;
  21. height: 100vh;
  22. font-size: 14px;
  23. color: #666;
  24. }
  25. body {
  26. min-width: 360px;
  27. background-color: #fff;
  28. display: flex;
  29. flex-flow: column nowrap;
  30. }
  31. body > header {
  32. display: flex;
  33. width: 95vw;
  34. color: white;
  35. background-color: #333;
  36. justify-content: space-between;
  37. height: 30px;
  38. align-items: center;
  39. padding: 0 15px;
  40. position: fixed;
  41. }
  42. body > .slider {
  43. height: 180px;
  44. }
  45. body > .slider > img {
  46. width: 100%;
  47. }
  48. nav {
  49. height: 200px;
  50. display: flex;
  51. flex-flow: row wrap;
  52. align-content: space-around;
  53. margin-top: 20px;
  54. }
  55. nav > div {
  56. display: flex;
  57. width: 25vw;
  58. flex-flow: column nowrap;
  59. align-items: center;
  60. }
  61. nav > div img {
  62. width: 50%;
  63. }
  64. nav > div > a:first-of-type {
  65. text-align: center;
  66. }
  67. .title {
  68. margin-top: 10px;
  69. font-size: 1.2rem;
  70. font-weight: normal;
  71. text-align: center;
  72. }
  73. .hot-goods {
  74. display: flex;
  75. margin-top: 10px;
  76. font-size: 0.8rem;
  77. flex-flow: row wrap;
  78. }
  79. .hot-goods img {
  80. width: 100%;
  81. }
  82. .hot-goods > .goods-img {
  83. padding: 10px;
  84. box-sizing: border-box;
  85. flex: 1 0 30vw;
  86. display: flex;
  87. flex-flow: column nowrap;
  88. justify-content: center;
  89. }
  90. .hot-goods > .goods-img > div {
  91. display: flex;
  92. justify-content: space-between;
  93. }
  94. .list-goods {
  95. display: flex;
  96. flex-flow: column nowrap;
  97. margin-top: 10px;
  98. font-size: 0.8rem;
  99. padding: 10px;
  100. box-sizing: border-box;
  101. border-top: 1px solid #555;
  102. }
  103. .list-goods > .goods-desc {
  104. display: flex;
  105. margin: 10px;
  106. }
  107. .list-goods > .goods-desc a {
  108. padding: 10px;
  109. box-sizing: border-box;
  110. }
  111. .list-goods > .goods-desc a:hover {
  112. color: skyblue;
  113. }
  114. .list-goods img {
  115. width: 100%;
  116. }
  117. footer {
  118. display: flex;
  119. position: fixed;
  120. bottom: 0;
  121. height: 55px;
  122. width: 100vw;
  123. background-color: ghostwhite;
  124. border-top: 1px solid #ccc;
  125. justify-content: space-around;
  126. align-items: center;
  127. }
  128. footer > a {
  129. display: flex;
  130. flex-direction: column;
  131. align-items: center;
  132. }
  133. footer > a:hover {
  134. color: chocolate;
  135. }
  136. footer > a > span:first-of-type {
  137. font-size: 1.8rem;
  138. }
  139. .goods-img > div >span:last-of-type {
  140. font-size: 1.5rem;
  141. }
  142. .goods-img > div >span:nth-of-type(2) {
  143. font-size: 1.5rem;
  144. }
  145. </style>
  146. </head>
  147. <body>
  148. <header>
  149. <a href="">LOGO</a>
  150. <span class="iconfont">&#xe638;</span>
  151. </header>
  152. <div class="slider">
  153. <img src="image/shop1.jpg" alt="" />
  154. </div>
  155. <nav>
  156. <div>
  157. <a href=""
  158. ><svg class="icon" aria-hidden="true">
  159. <use xlink:href="#icon-1"></use></svg
  160. ></a>
  161. <a href="">男宝宝</a>
  162. </div>
  163. <div>
  164. <a href=""
  165. ><svg class="icon" aria-hidden="true">
  166. <use xlink:href="#icon-9"></use></svg
  167. ></a>
  168. <a href="">女宝宝</a>
  169. </div>
  170. <div>
  171. <a href=""
  172. ><svg class="icon" aria-hidden="true">
  173. <use xlink:href="#icon-4"></use></svg
  174. ></a>
  175. <a href="">连体衣</a>
  176. </div>
  177. <div>
  178. <a href=""
  179. ><svg class="icon" aria-hidden="true">
  180. <use xlink:href="#icon-7"></use></svg
  181. ></a>
  182. <a href="">裤子</a>
  183. </div>
  184. <div>
  185. <a href=""
  186. ><svg class="icon" aria-hidden="true">
  187. <use xlink:href="#icon-2"></use></svg
  188. ></a>
  189. <a href="">袜子</a>
  190. </div>
  191. <div>
  192. <a href=""
  193. ><svg class="icon" aria-hidden="true">
  194. <use xlink:href="#icon-6"></use></svg
  195. ></a>
  196. <a href="">连衣裙</a>
  197. </div>
  198. <div>
  199. <a href=""
  200. ><svg class="icon" aria-hidden="true">
  201. <use xlink:href="#icon-8"></use></svg
  202. ></a>
  203. <a href="">裙子</a>
  204. </div>
  205. <div>
  206. <a href=""
  207. ><svg class="icon" aria-hidden="true">
  208. <use xlink:href="#icon-5"></use></svg
  209. ></a>
  210. <a href="">团购</a>
  211. </nav>
  212. <h2 class="title">热销商品</h2>
  213. <div class="hot-goods">
  214. <div class="goods-img">
  215. <a href=""><img src="image/dou.jpg" alt="" /></a>
  216. <p>巴布豆</p>
  217. <div>
  218. <span>99&nbsp;元</span>
  219. <span class="iconfont">&#xe65a;</span>
  220. <span class="iconfont">&#xe640;</span>
  221. </div>
  222. </div>
  223. <div class="goods-img">
  224. <a href=""><img src="image/dou.jpg" alt="" /></a>
  225. <p>巴布豆</p>
  226. <div>
  227. <span>99&nbsp;元</span>
  228. <span class="iconfont">&#xe640;</span>
  229. </div>
  230. </div>
  231. <div class="goods-img">
  232. <a href=""><img src="image/dou.jpg" alt="" /></a>
  233. <p>巴布豆</p>
  234. <div>
  235. <span>99&nbsp;元</span>
  236. <span class="iconfont">&#xe640;</span>
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. <h2 class="title">
  242. 商品列表<a href=""><img src="image/logo.jpg" height="17vw" alt="" /></a>
  243. </h2>
  244. <div class="list-goods">
  245. <div class="goods-desc">
  246. <a href=""><img src="image/yf.jpg" alt="" height="130vw" /></a>
  247. <a href=""
  248. >男童T恤2020秋装新款假两件宝宝长袖上衣小童打底衫儿童洋气衣服............................</a
  249. >
  250. </div>
  251. <div class="goods-desc">
  252. <a href=""><img src="image/yf.jpg" alt="" height="130vw" /></a>
  253. <a href=""
  254. >男童T恤2020秋装新款假两件宝宝长袖上衣小童打底衫儿童洋气衣服..........................</a
  255. >
  256. </div>
  257. <div class="goods-desc">
  258. <a href=""><img src="image/yf.jpg" alt="" height="130vw" /></a>
  259. <a href=""
  260. >男童T恤2020秋装新款假两件宝宝长袖上衣小童打底衫儿童洋气衣服..........................</a
  261. >
  262. </div>
  263. </div>
  264. <footer>
  265. <a href="">
  266. <span class="iconfont hot">&#xe63d;</span>
  267. <span>首页</span>
  268. </a>
  269. <a href="">
  270. <span class="iconfont hot">&#xe62f;</span>
  271. <span>分类</span>
  272. </a>
  273. <a href="">
  274. <span class="iconfont hot">&#xe645;</span>
  275. <span>订单</span>
  276. </a>
  277. <a href="">
  278. <span class="iconfont hot">&#xe625;</span>
  279. <span>客服</span>
  280. </a>
  281. </footer>
  282. </body>
  283. </html>

运行结果


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