利用flex布局进行仿写移动端苏宁易购首页

  • 完善移动端京东首页 http://easys.ltd/jd/
  • 仿写移动端苏宁首页 http://easys.ltd/sn

首页代码

index.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>苏宁易购首页</title>
  7. <link rel="stylesheet" href="css/index.css">
  8. </head>
  9. <body>
  10. <!-- 下载提示 -->
  11. <div class="headDown">
  12. <a href="https://c.m.suning.com/channelwap.htm?appid=1&packnversion=337&channelcode=40156&wap_source=%E6%98%93%E8%B4%AD%E7%AB%99%E5%86%85wap%E9%A6%96%E9%A1%B5%E9%A1%B6%E9%83%A8%E4%B8%8B%E8%BD%BD%E5%A4%B4&wap_medium=40156&wap_content=&wap_term=&wap_campaign=&downflag=0&adTypeCode=1002&adId=https%3A%2F%2Fm.suning.com%2F">
  13. <span></span>
  14. <img src="https://image.suning.cn/uimg/cms/img/161275688582112536.jpg" alt="">
  15. </a>
  16. </div>
  17. <!-- 头部菜单 -->
  18. <div class="sn-nav">
  19. <div class="nav-bg">
  20. <img src="https://image1.suning.cn/uimg/cms/img/161243730178975729.png">
  21. </div>
  22. <div class="top-type">
  23. <div class="content-wrap-one">
  24. <a href=""><img src="https://image2.suning.cn/uimg/cms/img/157199320847433454.png" alt=""></a>
  25. <a href=""><img src="https://image2.suning.cn/uimg/cms/img/161675232602234223.gif" alt=""></a>
  26. <a href=""><img src="https://image2.suning.cn/uimg/cms/img/157199321817918653.png" alt=""></a>
  27. </div>
  28. <div class="content-wrap-two">
  29. <form action="">
  30. <span class="iconfont "></span>
  31. <input class="searchInput" name="index_none_header_sysc" type="text" placeholder="空调爆款满千减百" autocomplete="off">
  32. </form>
  33. </div>
  34. </div>
  35. </div>
  36. <!-- 主体区域 -->
  37. <div class="main">
  38. <!-- 主导航区 -->
  39. <div class="enter-list">
  40. <ul class="fix">
  41. <li>
  42. <a href="#">
  43. <img src="https://image2.suning.cn/uimg/cms/img/161294178174781132.png?from=mobile" alt="">
  44. <span>苏宁秒杀</span>
  45. </a>
  46. </li>
  47. <li>
  48. <a href="#">
  49. <img src="https://image1.suning.cn/uimg/cms/img/161293951076282456.png?from=mobile" alt="">
  50. <span>苏宁超市</span>
  51. </a>
  52. </li>
  53. <li>
  54. <a href="#">
  55. <img src="https://image1.suning.cn/uimg/cms/img/161294179334814175.png?from=mobile" alt="">
  56. <span>苏宁拼购</span>
  57. </a>
  58. </li>
  59. <li>
  60. <a href="#">
  61. <img src="https://image2.suning.cn/uimg/cms/img/161293957567317395.png?from=mobile" alt="">
  62. <span>手机数码</span>
  63. </a>
  64. </li>
  65. <li>
  66. <a href="#">
  67. <img src="https://image3.suning.cn/uimg/cms/img/161293958842515136.png?from=mobile" alt="">
  68. <span>苏宁家电</span>
  69. </a>
  70. </li>
  71. <li>
  72. <a href="#">
  73. <img src="https://image1.suning.cn/uimg/cms/img/161293959950045622.png?from=mobile" alt="">
  74. <span>免费水果</span>
  75. </a>
  76. </li>
  77. <li>
  78. <a href="#">
  79. <img src="https://image2.suning.cn/uimg/cms/img/161293961484173843.png?from=mobile" alt="">
  80. <span>super会员</span>
  81. </a>
  82. </li>
  83. <li>
  84. <a href="#">
  85. <img src="https://image1.suning.cn/uimg/cms/img/161293963977525820.png?from=mobile" alt="">
  86. <span>签到有礼</span>
  87. </a>
  88. </li>
  89. <li>
  90. <a href="#">
  91. <img src="https://image2.suning.cn/uimg/cms/img/161293965567020138.png?from=mobile" alt="">
  92. <span>领券中心</span>
  93. </a>
  94. </li>
  95. <li>
  96. <a href="#">
  97. <img src="https://image2.suning.cn/uimg/cms/img/161293968063152286.png?from=mobile" alt="">
  98. <span>更多频道</span>
  99. </a>
  100. </li>
  101. </ul>
  102. </div>
  103. <!-- 新人礼包 -->
  104. <div class="newImgFloor-content">
  105. <a href="https://newmem.suning.com/newmem-web/nm/PAGE518604586267131904.htm">
  106. <img src="https://image1.suning.cn/uimg/cms/img/160415964665844208.png">
  107. </a>
  108. <a href="https://newmem.suning.com/newmem-web/nm/PAGE518604586267131904.htm">
  109. <img src="https://image3.suning.cn/uimg/cms/img/160415965447533335.gif">
  110. </a>
  111. <a href="https://newmem.suning.com/newmem-web/nm/PAGE518604586267131904.htm">
  112. <img src="https://image1.suning.cn/uimg/cms/img/160415966314573447.gif">
  113. </a>
  114. </div>
  115. <!-- 商品列表 -->
  116. <div class="guessUlike">
  117. <a class="title" href="https://c.m.suning.com/phbIndex3.html">
  118. <img src="https://image3.suning.cn/uimg/cms/img/157793128909842388.png?format=_is_1242w_100h.webp">
  119. </a>
  120. <ul>
  121. <li class="item">
  122. <a href="">
  123. <img src="https://imgservice.suning.cn/uimg1/b2c/atmosphere/7rUkk6cK3SCZdMISYTbPSQ.png?format=_is_300w_300h_4e.webp" alt="">
  124. <p>伊利 安慕希高端PET酸牛奶原味礼盒装230g*10盒 希腊风味营养学生成人早餐奶酸奶</p>
  125. <div class="price">
  126. <span class="flag"></span>
  127. <span class="pre-price">78</span>
  128. <span class="price-comments">25万+评价</span>
  129. </div>
  130. </a>
  131. </li>
  132. <li class="item">
  133. <a href="">
  134. <img src="https://imgservice.suning.cn/uimg1/b2c/image/onlVKphMGZSM57CgxO53yg.png?format=_is_300w_300h_4e.webp" alt="">
  135. <p>精灵TG_C1D国米定制</p>
  136. <div class="price">
  137. <span class="flag"></span>
  138. <span class="pre-price">78</span>
  139. <span class="price-comments">25万+评价</span>
  140. </div>
  141. </a>
  142. </li>
  143. <li class="item">
  144. <a href="">
  145. <img src="https://imgservice.suning.cn/uimg1/b2c/image/WHVdqX-XWOrflA07JiOoIw.jpg?format=_is_300w_300h_4e.webp" alt="">
  146. <p>中粮 初萃玉米胚芽油5L+400ml 物理压榨 一级桶装玉米油 非转基因 食用油粮油</p>
  147. <div class="price">
  148. <span class="flag"></span>
  149. <span class="pre-price">79</span>
  150. <span class="price-comments">5.4万+评价</span>
  151. </div>
  152. </a>
  153. </li>
  154. <li class="item">
  155. <a href="">
  156. <img src="https://imgservice.suning.cn/uimg1/b2c/atmosphere/rPmiXMbXtGFr2p4fDG2LcQ.png?format=_is_300w_300h_4e.webp" alt="">
  157. <p>雕牌超效加酶洗衣粉3.008kg深层去渍加酶增效无磷环保容量更多生活更美</p>
  158. <div class="price">
  159. <span class="flag"></span>
  160. <span class="pre-price">24.8</span>
  161. <span class="price-comments">1.6万+评价</span>
  162. </div>
  163. </a>
  164. </li>
  165. <li class="item">
  166. <a href="">
  167. <img src="https://imgservice.suning.cn/uimg1/b2c/atmosphere/7rUkk6cK3SCZdMISYTbPSQ.png?format=_is_300w_300h_4e.webp" alt="">
  168. <p>伊利 安慕希高端PET酸牛奶原味礼盒装230g*10盒 希腊风味营养学生成人早餐奶酸奶</p>
  169. <div class="price">
  170. <span class="flag"></span>
  171. <span class="pre-price">78</span>
  172. <span class="price-comments">25万+评价</span>
  173. </div>
  174. </a>
  175. </li>
  176. <li class="item">
  177. <a href="">
  178. <img src="https://imgservice.suning.cn/uimg1/b2c/image/_Ob1Ce4BkgbQ7Q-sG1sVXQ.jpg?format=_is_300w_300h_4e.webp" alt="">
  179. <p>美素佳儿(Friso)儿童配方牛奶粉 4段(3-6岁适用)900克罐装(荷兰原装进口)</p>
  180. <div class="price">
  181. <span class="flag"></span>
  182. <span class="pre-price">199</span>
  183. <span class="price-comments">12万+评价</span>
  184. </div>
  185. </a>
  186. </li>
  187. <li class="item">
  188. <a href="">
  189. <img src="https://imgservice.suning.cn/uimg1/b2c/image/UuBgXj2X962T1FOLWT8rnA.jpg?format=_is_300w_300h_4e.webp" alt="">
  190. <p>苏宁锦鲤礼包AH</p>
  191. <div class="price">
  192. <span class="flag"></span>
  193. <span class="pre-price">50</span>
  194. <span class="price-comments">30+评价</span>
  195. </div>
  196. </a>
  197. </li>
  198. <li class="item">
  199. <a href="">
  200. <img src="https://uimgproxy.suning.cn/uimg1/pcpv/pcpv/2021/03/27/11/iwoghBannerPicture/YE9dl7Vfhi1616815773607.png?format=_is_300w_300h_4e.webp" alt="">
  201. <p>bull公牛开关插座86型G07香槟金墙壁二三插五孔电源插座面板带单控开关空调16A电脑电视插座套餐 错位五孔 G07香槟金</p>
  202. <div class="price">
  203. <span class="flag"></span>
  204. <span class="pre-price">13.3</span>
  205. <span class="price-comments">1.5万+评价</span>
  206. </div>
  207. </a>
  208. </li>
  209. <li class="item">
  210. <a href="">
  211. <img src="https://uimgproxy.suning.cn/uimg1/pcpv/pcpv/2021/03/27/11/iwoghBannerPicture/bTMkJh8gUP1616816937568.png?format=_is_300w_300h_4e.webp" alt="">
  212. <p>伊利 安慕希高端PET酸牛奶原味礼盒装230g*10盒 希腊风味营养学生成人早餐奶酸奶</p>
  213. <div class="price">
  214. <span class="flag"></span>
  215. <span class="pre-price">78</span>
  216. <span class="price-comments">25万+评价</span>
  217. </div>
  218. </a>
  219. </li>
  220. <li class="item">
  221. <a href="">
  222. <img src="https://imgservice.suning.cn/uimg1/b2c/image/6eHoPUG-NfV4rMf6NpcC2w.jpg?format=_is_300w_300h_4e.webp" alt="">
  223. <p>百度小度在家智能屏X8红色8寸高清大屏 影音娱乐智慧屏 向往的生活同款,带屏智能音箱 WiFi/蓝牙音响 平板电脑学习机</p>
  224. <div class="price">
  225. <span class="flag"></span>
  226. <span class="pre-price">599</span>
  227. <span class="price-comments">600+评价</span>
  228. </div>
  229. </a>
  230. </li>
  231. </ul>
  232. </div>
  233. <img width="100%" src="https://res.suning.cn/project/cmsWeb/suning/wap/v7/images/snlogo.png?from=mobile" alt="">
  234. </div>
  235. <!-- 底部提示登录信息 -->
  236. <div class="to-login">
  237. <a href="">
  238. <img src="https://image3.suning.cn/uimg/cms/img/157588645542963955.png">
  239. </a>
  240. </div>
  241. <!-- 底部tab栏 -->
  242. <div class="footerTab">
  243. <ul>
  244. <li class="item">
  245. <a href="">
  246. <img src="https://image1.suning.cn/uimg/cms/img/157543975265772267.png?from=mobile" alt="">
  247. <span>猜你喜欢</span>
  248. </a>
  249. </li>
  250. <li class="item">
  251. <a href="">
  252. <img src="https://image1.suning.cn/uimg/cms/img/157562573743964714.png?from=mobile" alt="">
  253. <span>分类</span>
  254. </a>
  255. </li>
  256. <li class="item">
  257. <a href="">
  258. <img src="https://image2.suning.cn/uimg/cms/img/157543978244974042.png?from=mobile" alt="">
  259. <span>排行榜</span>
  260. </a>
  261. </li>
  262. <li class="item">
  263. <a href="">
  264. <img src="https://image1.suning.cn/uimg/cms/img/157543979328589256.png?from=mobile" alt="">
  265. <span>购物车</span>
  266. </a>
  267. </li>
  268. <li class="item">
  269. <a href="">
  270. <img src="https://image2.suning.cn/uimg/cms/img/157543980229048220.png?from=mobile" alt="">
  271. <span>我的易购</span>
  272. </a>
  273. </li>
  274. </ul>
  275. </div>
  276. <!-- 侧边漂浮物 -->
  277. <div class="sidebar">
  278. <img class="lqwxImg" src="https://image1.suning.cn/uimg/cms/img/160976296805480325.gif" />
  279. <img class="common-right" src="https://image.suning.cn/uimg/cms/img/160756203309703632.gif" />
  280. </div>
  281. </body>
  282. </html>

index.css

  1. @import url('reset.css');
  2. /* 下载提示 */
  3. .headDown {
  4. width: 100%;
  5. font-size: 0;
  6. }
  7. .headDown img {
  8. width: 100%;
  9. }
  10. /* 头部菜单 */
  11. .sn-nav {
  12. height: 3.6rem;
  13. margin: 0 auto;
  14. position: relative;
  15. font-size: 0.48rem;
  16. line-height: 1.76rem;
  17. overflow: hidden;
  18. }
  19. .sn-nav .nav-bg {
  20. position: absolute;
  21. top: 0;
  22. left: 0;
  23. width: 100%;
  24. height: 3.6rem;
  25. overflow: hidden;
  26. }
  27. .sn-nav .nav-bg img {
  28. position: absolute;
  29. bottom: 0;
  30. width: 100%;
  31. height: 5.2rem;
  32. }
  33. .sn-nav .top-type {
  34. position: relative;
  35. margin: 0 0.4rem;
  36. }
  37. .sn-nav .top-type .content-wrap-one {
  38. height: 1.76rem;
  39. display: flex;
  40. flex: 1;
  41. justify-content: space-between;
  42. align-items: center;
  43. }
  44. .sn-nav .top-type .content-wrap-one img {
  45. width: 100%;
  46. }
  47. .sn-nav .top-type .content-wrap-one a {
  48. width: 0.72rem;
  49. height: 1.52rem;
  50. }
  51. .sn-nav .top-type .content-wrap-one a:nth-of-type(2) {
  52. flex: 2;
  53. text-align: center;
  54. }
  55. .sn-nav .top-type .content-wrap-one a:nth-of-type(2) img {
  56. width: 7.8rem;
  57. height: 1.52rem;
  58. }
  59. .sn-nav .top-type .content-wrap-two {
  60. width: 100%;
  61. height: 1.4rem;
  62. margin: 0.2rem 0;
  63. padding: 0 .48rem;
  64. background-color: #FFF;
  65. border-radius: 2rem;
  66. }
  67. .sn-nav .top-type .content-wrap-two form {
  68. height: 1.4rem;
  69. line-height: 1.4rem;
  70. }
  71. .searchInput {
  72. margin-left: 1rem;
  73. border: 0;
  74. }
  75. /* 主体区域 */
  76. .main {
  77. min-width: 320px;
  78. max-width: 750px;
  79. margin: 0 0.4rem 4rem;
  80. }
  81. /* 主导航区 */
  82. .main .enter-list .fix {
  83. display: flex;
  84. flex-wrap: wrap;
  85. justify-content: center;
  86. }
  87. .main .enter-list .fix li {
  88. flex: 1 1 20%;
  89. }
  90. .main .enter-list .fix li a {
  91. height: 2.84rem;
  92. display: flex;
  93. align-items: center;
  94. justify-content: flex-end;
  95. flex-direction: column;
  96. }
  97. .main .enter-list .fix a img {
  98. width: 1.68rem;
  99. height: 1.68rem;
  100. }
  101. .main .enter-list .fix a span {
  102. line-height: .56rem;
  103. height: .56rem;
  104. overflow: hidden;
  105. font-size: .44rem;
  106. margin-top: .1rem;
  107. color: #666;
  108. text-align: center;
  109. }
  110. /* 新人优惠 */
  111. .main .newImgFloor-content {
  112. height: 4.68rem;
  113. border-radius: 2rem;
  114. display: flex;
  115. justify-content: space-around;
  116. margin: 0.6rem 0;
  117. }
  118. .main .newImgFloor-content a {
  119. flex: 1;
  120. }
  121. .main .newImgFloor-content a:first-of-type {
  122. flex: 2;
  123. }
  124. .main .newImgFloor-content a:nth-of-type(2) {
  125. margin: 0 0.1rem;
  126. }
  127. .main .newImgFloor-content a img {
  128. width: 100%;
  129. height: 4.68rem;
  130. }
  131. /* 商品列表 */
  132. .main .guessUlike a img {
  133. width: 100%;
  134. }
  135. .main .guessUlike ul {
  136. font-size: 1rem;
  137. display: flex;
  138. /* 允许换行 */
  139. flex-wrap: wrap;
  140. }
  141. .main .guessUlike .item {
  142. flex: 1 1 calc(50% - 2rem);
  143. background-color: #fff;
  144. overflow: hidden;
  145. display: flex;
  146. flex-flow: column nowrap;
  147. margin-bottom: 0.3rem;
  148. border-radius: 0.4rem;
  149. }
  150. .main .guessUlike .item:nth-child(even) {
  151. margin-left: 0.3rem;
  152. }
  153. .main .guessUlike .item img {
  154. width: 100%;
  155. }
  156. .main .guessUlike .item a p {
  157. height: 1.6rem;
  158. font-size: 0.5rem;
  159. padding: 0 0.2rem;
  160. font-weight: bolder;
  161. color: #555;
  162. line-height: 0.8rem;
  163. overflow: hidden;
  164. text-overflow: ellipsis;
  165. display: -webkit-box;
  166. -webkit-line-clamp: 2;
  167. -webkit-box-orient: vertical;
  168. }
  169. .main .guessUlike .item .price {
  170. display: flex;
  171. margin: 0.8rem 0.4rem 0.3rem;
  172. }
  173. .main .guessUlike .item .price .flag,
  174. .pre-price {
  175. font-weight: bolder;
  176. color: red;
  177. font-size: 0.66rem;
  178. }
  179. .main .guessUlike .item .price .flag {
  180. font-size: 0.5rem;
  181. }
  182. .main .guessUlike .item .price .price-comments {
  183. color: #999999;
  184. margin-left: .26rem;
  185. font-weight: normal;
  186. font-size: .4rem;
  187. }
  188. /* 提示登录框 */
  189. .to-login {
  190. min-width: 320px;
  191. max-width: 750px;
  192. position: fixed;
  193. bottom: 1.8rem;
  194. }
  195. .to-login img {
  196. width: 100%;
  197. }
  198. /* 底部tab栏 */
  199. .footerTab {
  200. min-width: 320px;
  201. max-width: 750px;
  202. width: 100%;
  203. height: 2rem;
  204. position: fixed;
  205. bottom: 0;
  206. margin: 0 auto;
  207. z-index: 199;
  208. border-top: 1px solid #EEE;
  209. background: #FFF;
  210. }
  211. .footerTab ul {
  212. display: flex;
  213. align-items: center;
  214. justify-content: center;
  215. }
  216. .footerTab ul li a {
  217. display: flex;
  218. flex-direction: column;
  219. flex: 1;
  220. text-align: center;
  221. width: 3rem;
  222. height: 2rem;
  223. background: #fff;
  224. }
  225. .footerTab ul li a img {
  226. width: .96rem;
  227. height: .96rem;
  228. margin: .24rem auto 0
  229. }
  230. .footerTab ul li a span {
  231. font-size: 0.4rem;
  232. color: #666;
  233. }
  234. .footerTab ul li:first-child span {
  235. color: #000000;
  236. font-weight: bold
  237. }
  238. /* 侧边漂浮物 */
  239. .lqwxImg {
  240. width: 2rem;
  241. height: 2rem;
  242. position: fixed;
  243. right: 0;
  244. top: 150px;
  245. }
  246. .common-right {
  247. width: 2rem;
  248. height: 2.9rem;
  249. position: fixed;
  250. right: 0;
  251. top: 300px;
  252. }

reset.css

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. li {
  7. list-style: none;
  8. }
  9. a {
  10. color: white;
  11. text-decoration: none;
  12. }
  13. body {
  14. min-width: 320px;
  15. max-width: 750px;
  16. font-family: Arial, Helvetica, STHeiTi, sans-serif;
  17. background: #f2f2f2;
  18. margin: 0 auto;
  19. }
  20. /* 媒体查询 */
  21. @media screen and (min-width:320px) {
  22. html {
  23. font-size: 21.33px
  24. }
  25. body {
  26. font-size: 12px
  27. }
  28. }
  29. @media screen and (min-width:360px) {
  30. html {
  31. font-size: 24px
  32. }
  33. body {
  34. font-size: 12px
  35. }
  36. }
  37. @media screen and (min-width:375px) {
  38. html {
  39. font-size: 25px
  40. }
  41. body {
  42. font-size: 12px
  43. }
  44. }
  45. @media screen and (min-width:384px) {
  46. html {
  47. font-size: 25.6px
  48. }
  49. body {
  50. font-size: 14px
  51. }
  52. }
  53. @media screen and (min-width:400px) {
  54. html {
  55. font-size: 26.67px
  56. }
  57. body {
  58. font-size: 14px
  59. }
  60. }
  61. @media screen and (min-width:414px) {
  62. html {
  63. font-size: 27.6px
  64. }
  65. body {
  66. font-size: 14px
  67. }
  68. }
  69. @media screen and (min-width:424px) {
  70. html {
  71. font-size: 28.27px
  72. }
  73. body {
  74. font-size: 14px
  75. }
  76. }
  77. @media screen and (min-width:480px) {
  78. html {
  79. font-size: 32px
  80. }
  81. body {
  82. font-size: 15.36px
  83. }
  84. }
  85. @media screen and (min-width:540px) {
  86. html {
  87. font-size: 36px
  88. }
  89. body {
  90. font-size: 17.28px
  91. }
  92. }
  93. @media screen and (min-width:720px) {
  94. html {
  95. font-size: 48px
  96. }
  97. body {
  98. font-size: 23.04px
  99. }
  100. }
  101. @media screen and (min-width:750px) {
  102. html {
  103. font-size: 50px
  104. }
  105. body {
  106. font-size: 24px
  107. }
  108. }

仿写实现效果:

通过仿写移动端苏宁易购首页发现,自己很多地方还是不够熟练和了解的,跟着老师进行仿写移动端京东首页很轻松,但到了自己布局的时候,往往出现各种问题,经过大半天的时间总算仿写的差不多,虽然整体页面效果还差的很远。

grid布局的相关属性

CSS 网格布局擅长于将一个页面划分为几个主要区域,以及定义这些区域的大小、位置、层次等关系(前提是HTML生成了这些区域)。

像表格一样,网格布局让我们能够按行或列来对齐元素。 然而在布局上,网格比表格更可能做到或更简单。 例如,网格容器的子元素可以自己定位,以便它们像CSS定位的元素一样,真正的有重叠和层次。

MDN 网格布局 参考网址

注意:flex布局是将项目全部转换成行内块元素,grid布局是将项目转换成块元素进行的。

1. 术语

序号术语描述
1网格容器dispaly:grid属性定义的元素
2网格项目网格容器的直接子元素
3网格区域由一个或多个单元格组成的矩形区域

2. 常用属性

序号属性描述
1grid-template-columns定义网格轨道中的列宽
2grid-template-rows定义网格轨道中的行高
3gap网格轨道间距
4grid-auto-flow项目在容器中的排列方向
5grid-auto-rows隐式网格单元的行高
6grid-auto-columns隐式网格单元的列宽
7grid-area定义网格区域
8place-items所有项目在网络单元中的对齐方式
9place-self某个项目在网络单元(含网格区域)中的对齐方式
10place-content项目在网格容器中的对齐方式

利用grid网格布局快速实现圣杯布局

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>圣杯布局</title>
  8. <style>
  9. body * {
  10. border: 1px solid #000;
  11. }
  12. body {
  13. display: grid;
  14. grid-template-columns: 15em 50vw 15em;
  15. grid-template-rows: 3em 80vh 3em;
  16. place-content: center;
  17. gap: 0.5em;
  18. }
  19. header,
  20. footer {
  21. grid-area: span 1 / span 3;
  22. }
  23. main {
  24. grid-area: 2 /2;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <header>header</header>
  30. <!-- 圣杯布局要求主体优先渲染 -->
  31. <main>在CSS布局中有一种经典的布局是圣杯布局</main>
  32. <aside class="left">left</aside>
  33. <aside class="right">right</aside>
  34. <footer>footer</footer>
  35. </body>
  36. </html>

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>常用术语</title>
  8. <style>
  9. /* 1. 网格容器: display:grid*/
  10. /* 2. 网格项目:容器的子元素 */
  11. /* 3. 网格单元: 有单元格和网格区域二种表现形式 */
  12. /* 4. 网格轨道: 有行轨与列轨之分 */
  13. /* 5. 轨道间距: 轨道间隙,根据轨道类型有: 行轨间隙,列轨间隙 */
  14. /* flex: 一维布局技术
  15. grid: 二维布局技术 */
  16. .container {
  17. /* 转为网格容器进行布局 */
  18. display: grid;
  19. border: 1px solid #000;
  20. padding: 0.5em;
  21. /* 3列,共6个项目 */
  22. /* 1. 设置轨道的列宽 */
  23. grid-template-columns: 10em 10em 10em;
  24. /* grid-template-columns: auto auto auto; */
  25. /* 2. 设置田轨道的行高 */
  26. /* 2行, 共6个元素,第一行有3列 */
  27. grid-template-rows: 5em 5em;
  28. /* 3. 设置轨道间的间隙 */
  29. /* gap: 水平 垂直 */
  30. /* gap: 0.5em 1em; */
  31. /* gap: 0.5em 0.5em; */
  32. gap: 0.5em;
  33. }
  34. .container > .item {
  35. /* 父级为grid容器,它内部的子元素自动成为grid项目 */
  36. background-color: lightcyan;
  37. border: 1px solid #000;
  38. padding: 0.5em;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <div class="container">
  44. <div class="item">item1</div>
  45. <div class="item">item2</div>
  46. <div class="item">item3</div>
  47. <div class="item">item4</div>
  48. <div class="item">item5</div>
  49. <div class="item">item6</div>
  50. </div>
  51. </body>
  52. </html>

更多相关文章

  1. RelativeLayout相对布局中的属性
  2. android 使用html5作布局文件: webview跟javascript交互
  3. Android(安卓)流式布局FlowLayout(搜索历史),多布局、删除、添加
  4. Android(安卓)P SystemUI之StatusBar UI布局status_bar.xml解析
  5. SlidingMenu和ActionBarSherlock结合做出出色的App布局,Facebook
  6. Android(安卓)UI系列 - 布局 - 目录
  7. android 布局式跑马灯,非TextView
  8. android布局文件中的include
  9. Android布局(序章)

随机推荐

  1. android ndk 入门实践
  2. android获取手机已经安装的app信息
  3. Android AudioManager修改设备默认音量
  4. Android手势滑动Tab
  5. Android Studio安装app 报错的问题It is
  6. android 中添加一个服务
  7. Android 获取屏幕宽高的两种方式
  8. 2013.04.10——— android 图片缓存之三c
  9. 获取安装的应用
  10. Android Studio使用笔记