Blogger Information
Blog 12
fans 1
comment 0
visits 9540
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PC端布局的通用解决方案and移动端布局解决方案
浪子修罗记录有趣的事
Original
803 people have browsed it

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>PC端布局的通用解决方案</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. a {
  14. color: #666666;
  15. text-decoration: none;
  16. }
  17. /* 把body转为flex */
  18. body {
  19. /* 最小宽度 */
  20. min-width: 680px;
  21. /* 转为弹性盒子 */
  22. display: flex;
  23. /* 主轴垂直方向,不换行 */
  24. flex-flow: column nowrap;
  25. }
  26. /* 页眉,页脚公共样式 */
  27. header,
  28. footer {
  29. height: 50px;
  30. background-color: bisque;
  31. }
  32. /* 把页眉转为flex */
  33. header {
  34. display: flex;
  35. /* 所有项目在交叉轴方向上居中显示 */
  36. align-items: center;
  37. }
  38. header > a {
  39. /* 禁止放大 允许收缩 100px宽度 */
  40. flex: 0 1 100px;
  41. /* 文本居中 */
  42. text-align: center;
  43. }
  44. /* logo 伪类选择第一个*/
  45. header > a:first-of-type {
  46. /* 给第一个A标签右边距80px */
  47. margin-right: 80px;
  48. }
  49. /* 登录 伪类选择最后一个*/
  50. header > a:last-of-type {
  51. /* 给最后一个A标签左边距自动铺满 */
  52. margin-left: auto;
  53. }
  54. /* 鼠标悬停时忽略logo */
  55. header > a:hover:not(:first-of-type) {
  56. color: lightcoral;
  57. }
  58. .container {
  59. min-height: 600px;
  60. /* 转为弹性盒子 */
  61. display: flex;
  62. /* 主轴横向方向,不换行 默认值,可以不用写 */
  63. flex-flow: row nowrap;
  64. margin: 10px auto;
  65. justify-content: center;
  66. }
  67. .container > aside,
  68. .container > main {
  69. background-color: lightcyan;
  70. padding: 10px;
  71. }
  72. .container > aside {
  73. /* 不放大 不收缩 宽200px */
  74. flex: 0 0 200px;
  75. }
  76. .container > main {
  77. /* 不放大 不收缩 宽600px */
  78. flex: 0 0 600px;
  79. /* 左右边距10px */
  80. margin: 0 10px;
  81. }
  82. footer {
  83. display: flex;
  84. /* 主轴垂直方向,不换行 */
  85. flex-flow: column nowrap;
  86. /* 文本居中 */
  87. text-align: center;
  88. }
  89. </style>
  90. </head>
  91. <body>
  92. <!-- 页眉 -->
  93. <header>
  94. <a href="">LOGO</a>
  95. <a href="">首页</a>
  96. <a href="">栏目1</a>
  97. <a href="">栏目2</a>
  98. <a href="">栏目3</a>
  99. <a href="">登录</a>
  100. </header>
  101. <!-- 主体 -->
  102. <div class="container">
  103. <!-- 左边栏 -->
  104. <aside>左边栏</aside>
  105. <!-- 主体 -->
  106. <main>主体内容</main>
  107. <!-- 右边栏 -->
  108. <aside>右边栏</aside>
  109. </div>
  110. <!-- 页脚 -->
  111. <footer>
  112. <p>
  113. 大赤水网 © 版权所有 (2016-2020)|ICP备案号:<a href=""
  114. >备了就有00000011</a
  115. >
  116. </p>
  117. <p>中国赤水 赤水大道 公安备案号:0000000111</p>
  118. </footer>
  119. </body>
  120. </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. <!-- 加载阿里字体图标 -->
  7. <link rel="stylesheet" href="css.css" />
  8. <title>移动端布局解决方案</title>
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box;
  14. }
  15. a {
  16. text-decoration: none;
  17. color: #666;
  18. }
  19. html {
  20. /* vw: 可视区宽度,100指百分比 */
  21. /* vh: 可视区高度,100指百分比 */
  22. width: 100vw;
  23. height: 100vh;
  24. font-size: 14px;
  25. color: #666;
  26. }
  27. body {
  28. min-width: 360px;
  29. background-color: #fff;
  30. display: flex;
  31. /* 主轴垂直方向,不换行 */
  32. flex-flow: column nowrap;
  33. }
  34. body > header {
  35. color: white;
  36. background-color: #333;
  37. height: 30px;
  38. display: flex;
  39. align-items: center;
  40. /* 两端对齐 */
  41. justify-content: space-between;
  42. /* 固定定位 */
  43. position: fixed;
  44. width: 100vw;
  45. padding: 0 15px;
  46. }
  47. body > .slider {
  48. height: 180px;
  49. }
  50. body > .slider > img {
  51. /* 宽高100% */
  52. width: 100%;
  53. height: 100%;
  54. }
  55. h2 {
  56. text-align: center;
  57. background-color: lightgray;
  58. height: 35px;
  59. }
  60. /* 主导航区 */
  61. nav {
  62. height: 200px;
  63. margin-bottom: 10px;
  64. /* 弹性盒子 */
  65. display: flex;
  66. /* 转为多行容器 */
  67. flex-flow: row wrap;
  68. /* 分散对齐 */
  69. align-content: space-around;
  70. }
  71. nav > div {
  72. /* 25% 一排四个 */
  73. width: 25vw;
  74. display: flex;
  75. flex-flow: column nowrap;
  76. align-items: center;
  77. }
  78. nav > div > a:first-of-type {
  79. text-align: center;
  80. }
  81. nav > div img {
  82. width: 50%;
  83. }
  84. /* 每个区域的标题样式 */
  85. .title {
  86. margin-top: 10px;
  87. font-size: 1.2rem;
  88. font-weight: normal;
  89. text-align: center;
  90. }
  91. /* 热销商品区 */
  92. .hot-goods {
  93. border-top: 1px solid #cdcdcd;
  94. margin-top: 10px;
  95. font-size: 0.8rem;
  96. display: flex;
  97. /* 水平多行容器 */
  98. flex-flow: row wrap;
  99. }
  100. .hot-goods img {
  101. width: 100%;
  102. }
  103. .hot-goods > .goods-img {
  104. /* 内边距并重置大小 */
  105. padding: 10px;
  106. box-sizing: border-box;
  107. /* 允许放大不允许缩小,否则项目不会换行,多行容器失效 */
  108. flex: 1 0 30vw;
  109. /* 再将每个商品描述转为flex */
  110. display: flex;
  111. /* 主轴垂直且不允许换行 */
  112. flex-flow: column nowrap;
  113. justify-content: center;
  114. }
  115. /* 商品描述的最后一个区域转flex,并设置项目在主轴上排列对齐方式 */
  116. .hot-goods > .goods-img > div {
  117. display: flex;
  118. /* 分散对齐 */
  119. justify-content: space-around;
  120. }
  121. /* 热销样式 */
  122. .hot {
  123. color: coral;
  124. }
  125. /* 商品列表区 */
  126. .list-goods {
  127. padding: 10px;
  128. border-top: 1px solid #cdcdcd;
  129. margin-top: 10px;
  130. font-size: 0.8rem;
  131. display: flex;
  132. /* 主轴必须是垂直 */
  133. flex-flow: column nowrap;
  134. }
  135. /* 每个项目也转为flex */
  136. .list-goods > .goods-desc {
  137. margin: 10px 0;
  138. display: flex;
  139. }
  140. /* 列表中每个项目的样式,加些间距 */
  141. .list-goods > .goods-desc > a {
  142. padding: 10px;
  143. box-sizing: border-box;
  144. }
  145. .list-goods > .goods-desc > a:last-of-type:hover {
  146. color: lightseagreen;
  147. }
  148. /* 图片全部适应项目空间 */
  149. .list-goods img {
  150. width: 100%;
  151. }
  152. body > footer {
  153. color: #666;
  154. background-color: #efefef;
  155. border-top: 1px solid #ccc;
  156. height: 55px;
  157. position: fixed;
  158. bottom: 0;
  159. width: 100vw;
  160. display: flex;
  161. /* 平均对齐 */
  162. justify-content: space-evenly;
  163. }
  164. body > footer a {
  165. margin-top: 10px;
  166. font-size: 0.8rem;
  167. display: flex;
  168. /* 垂直排列不换行 */
  169. flex-flow: column nowrap;
  170. /* 交叉轴项目居中显示 */
  171. align-items: center;
  172. }
  173. body > footer a > span:first-of-type {
  174. /* 图标字体应该大一些 */
  175. font-size: 1.6rem;
  176. }
  177. </style>
  178. </head>
  179. <body>
  180. <!-- 页眉 -->
  181. <header>
  182. <a href="">LOGO</a>
  183. <span class="iconfont"></span>
  184. </header>
  185. <!-- 轮播图区 -->
  186. <div class="slider">
  187. <img src="images/banner.jpg" alt="" />
  188. </div>
  189. <!-- 主导航区 -->
  190. <nav>
  191. <div>
  192. <a href=""><img src="images/link1.webp" alt="" /></a>
  193. <a href="">京东超市</a>
  194. </div>
  195. <div>
  196. <a href=""><img src="images/link2.webp" alt="" /></a>
  197. <a href="">服装百货</a>
  198. </div>
  199. <div>
  200. <a href=""><img src="images/link3.webp" alt="" /></a>
  201. <a href="">数码精品</a>
  202. </div>
  203. <div>
  204. <a href=""><img src="images/link4.webp" alt="" /></a>
  205. <a href="">优惠劵</a>
  206. </div>
  207. <div>
  208. <a href=""><img src="images/link1.webp" alt="" /></a>
  209. <a href="">超市精选</a>
  210. </div>
  211. <div>
  212. <a href=""><img src="images/link2.webp" alt="" /></a>
  213. <a href="">服装百货</a>
  214. </div>
  215. <div>
  216. <a href=""><img src="images/link3.webp" alt="" /></a>
  217. <a href="">数码精品</a>
  218. </div>
  219. <div>
  220. <a href=""><img src="images/link4.webp" alt="" /></a>
  221. <a href="">优惠劵</a>
  222. </div>
  223. </nav>
  224. <!-- 热销商品 -->
  225. <h2>
  226. 热销商品区<span class="iconfont hot" style="color: coral;"></span>
  227. </h2>
  228. <div class="hot-goods">
  229. <div class="goods-img">
  230. <a href=""><img src="images/goods1.jpg" alt="" /></a>
  231. <p>Apple iPhone 11 128G</p>
  232. <div>
  233. <span>6299 元</span>
  234. <span class="iconfont hot"></span>
  235. </div>
  236. </div>
  237. <div class="goods-img">
  238. <a href=""><img src="images/goods1.jpg" alt="" /></a>
  239. <p>Apple iPhone X 512G</p>
  240. <div>
  241. <span>8299 元</span>
  242. <span class="iconfont hot"></span>
  243. </div>
  244. </div>
  245. <div class="goods-img">
  246. <a href=""><img src="images/goods2.jpg" alt="" /></a>
  247. <p>华为笔记本电脑</p>
  248. <div>
  249. <span>5699 元</span>
  250. <span class="iconfont hot"></span>
  251. </div>
  252. </div>
  253. <div class="goods-img">
  254. <a href=""><img src="images/goods2.jpg" alt="" /></a>
  255. <p>小米笔记本电脑</p>
  256. <div>
  257. <span>3999 元</span>
  258. <span class="iconfont hot"></span>
  259. </div>
  260. </div>
  261. <div class="goods-img">
  262. <a href=""><img src="images/goods2.jpg" alt="" /></a>
  263. <p>联想笔记本电脑</p>
  264. <div>
  265. <span>4399 元</span>
  266. <span class="iconfont hot"></span>
  267. </div>
  268. </div>
  269. </div>
  270. <!-- 商品列表区 -->
  271. <h2 class="title">
  272. 商品列表<span class="iconfont hot" style="color: coral;"></span>
  273. </h2>
  274. <div class="list-goods">
  275. <div class="goods-desc">
  276. <a href=""><img src="images/goods4.jpg" alt="" /></a>
  277. <a href=""
  278. >[白条12期免息]Apple苹果iPhone 11 手机 128G 全网通, 免费领取500元话费,
  279. 今天17:00下单,明晨12:00之前送达,7天无理由退货,官方提供售后
  280. <span class="iconfont hot" style="vertical-align: middle;"
  281. ></span
  282. ></a
  283. >
  284. </div>
  285. <div class="goods-desc">
  286. <a href=""><img src="images/goods3.jpg" alt="" /></a>
  287. <a href=""
  288. >[白条6期免息]Apple洗衣机,专业清洗苹果手机,
  289. 苹果电脑,iPad,洗好保证不能用, 免费领取500元保险费,
  290. 今天17:00下单,明晨12:00之前送达,7天无理由退货,官方提供售后
  291. <span class="iconfont hot" style="vertical-align: middle;"
  292. ></span
  293. ></a
  294. >
  295. </div>
  296. <div class="goods-desc">
  297. <a href=""><img src="images/goods5.png" alt="" /></a>
  298. <a href=""
  299. >[白条6期免息]Apple苹果iPhone 11 手机 128G 全网通, 免费领取500元话费,
  300. 今天17:00下单,明晨12:00之前送达,7天无理由退货,官方提供售后
  301. <span class="iconfont hot" style="vertical-align: middle;"
  302. ></span
  303. ></a
  304. >
  305. </div>
  306. <div class="goods-desc">
  307. <a href=""><img src="images/goods2.jpg" alt="" /></a>
  308. <a href=""
  309. >华为笔记本MateBook 14 全面屏轻薄性能笔记本电脑 十代酷睿(i5 16G 512G
  310. MX250 触控屏 多屏协同)灰<span
  311. class="iconfont hot"
  312. style="vertical-align: middle;"
  313. ></span
  314. ></a
  315. >
  316. </div>
  317. </div>
  318. <footer>
  319. <a href="">
  320. <span class="iconfont hot"></span>
  321. <span>首页</span>
  322. </a>
  323. <a href="">
  324. <span class="iconfont hot"></span>
  325. <span>分类</span>
  326. </a>
  327. <a href="">
  328. <span class="iconfont hot"></span>
  329. <span>购物车</span>
  330. </a>
  331. <a href="">
  332. <span class="iconfont hot"></span>
  333. <span>未登录</span>
  334. </a>
  335. </footer>
  336. </body>
  337. </html>

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