博客列表 >网页布局实战演练

网页布局实战演练

Yang_Sir
Yang_Sir原创
2020年04月16日 19:54:56481浏览

网页布局实战演练

1. 网络相册

  • grid布局,使用grid自动填充,适应页面展示。
  • 全部源码如下:
  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. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. a {
  14. text-decoration: none;
  15. }
  16. body {
  17. background-color: #f3f3e6;
  18. }
  19. h1 {
  20. text-align: center;
  21. color: #0080ff;
  22. margin-top: 30px;
  23. letter-spacing: 5px;
  24. font-size: 2rem;
  25. font-weight: 650;
  26. text-shadow: 2px 2px 2px yellowgreen;
  27. }
  28. .container {
  29. min-width: 100vw;
  30. min-height: 100vh;
  31. padding: 50px;
  32. display: grid;
  33. grid-template-columns: repeat(auto-fill, 250px);
  34. grid-template-rows: repeat(auto-fill, 280px);
  35. justify-content: space-around;
  36. align-content: space-around;
  37. gap: 25px;
  38. }
  39. .container > .item {
  40. border-radius: 10px;
  41. background-color: #80ffff;
  42. padding: 10px;
  43. display: flex;
  44. flex-flow: column nowrap;
  45. align-items: center;
  46. justify-content: space-around;
  47. }
  48. .container img {
  49. width: 100%;
  50. }
  51. .container > .item:hover {
  52. box-shadow: 0 0 10px #0000ff;
  53. width: calc(100% * 1.02);
  54. background-color: rgb(223, 236, 150);
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <h1>我的相册</h1>
  60. <div class="container">
  61. <div class="item">
  62. <a href=""><img src="images/1.jpg" alt="" /></a>
  63. <a href="">太极</a>
  64. </div>
  65. <div class="item">
  66. <a href=""><img src="images/1.jpg" alt="" /></a>
  67. <a href="">太极</a>
  68. </div>
  69. <div class="item">
  70. <a href=""><img src="images/1.jpg" alt="" /></a>
  71. <a href="">太极</a>
  72. </div>
  73. <div class="item">
  74. <a href=""><img src="images/1.jpg" alt="" /></a>
  75. <a href="">太极</a>
  76. </div>
  77. <div class="item">
  78. <a href=""><img src="images/1.jpg" alt="" /></a>
  79. <a href="">太极</a>
  80. </div>
  81. <div class="item">
  82. <a href=""><img src="images/1.jpg" alt="" /></a>
  83. <a href="">太极</a>
  84. </div>
  85. <div class="item">
  86. <a href=""><img src="images/1.jpg" alt="" /></a>
  87. <a href="">太极</a>
  88. </div>
  89. <div class="item">
  90. <a href=""><img src="images/1.jpg" alt="" /></a>
  91. <a href="">太极</a>
  92. </div>
  93. <div class="item">
  94. <a href=""><img src="images/1.jpg" alt="" /></a>
  95. <a href="">太极</a>
  96. </div>
  97. <div class="item">
  98. <a href=""><img src="images/1.jpg" alt="" /></a>
  99. <a href="">太极</a>
  100. </div>
  101. <div class="item">
  102. <a href=""><img src="images/1.jpg" alt="" /></a>
  103. <a href="">太极</a>
  104. </div>
  105. <div class="item">
  106. <a href=""><img src="images/1.jpg" alt="" /></a>
  107. <a href="">太极</a>
  108. </div>
  109. </div>
  110. </body>
  111. </html>

效果图:

2. 仿栅格布局组件

  • 使用grid布局中的网格区域选择填充,实现组件开发栅格布局
  • 组件源代码:
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. .body {
  7. max-width: 100vw;
  8. min-height: 100vh;
  9. display: flex;
  10. justify-content: center;
  11. align-items: center;
  12. }
  13. .container {
  14. display: grid;
  15. gap: 5px 0;
  16. }
  17. .row {
  18. display: grid;
  19. grid-template-columns: repeat(12, 1fr);
  20. gap: 5px;
  21. }
  22. .row > .item {
  23. border: 1px solid;
  24. background-color: #80ff80;
  25. }
  26. .col-2 {
  27. grid-column-end: span 2;
  28. }
  29. .col-3 {
  30. grid-column-end: span 3;
  31. }
  32. .col-4 {
  33. grid-column-end: span 4;
  34. }
  35. .col-5 {
  36. grid-column-end: span 5;
  37. }
  38. .col-6 {
  39. grid-column-end: span 6;
  40. }
  41. .col-7 {
  42. grid-column-end: span 7;
  43. }
  44. .col-8 {
  45. grid-column-end: span 8;
  46. }
  47. .col-9 {
  48. grid-column-end: span 9;
  49. }
  50. .col-10 {
  51. grid-column-end: span 10;
  52. }
  53. .col-11 {
  54. grid-column-end: span 11;
  55. }
  56. .col-12 {
  57. grid-column-end: span 12;
  58. }
  • 演示用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="col.css" />
    8. </head>
    9. <body>
    10. <div class="container">
    11. <div class="row">
    12. <div class="item col-2">2</div>
    13. <div class="item col-4">4</div>
    14. <div class="item col-6">6</div>
    15. </div>
    16. <div class="row">
    17. <div class="item col-4">2</div>
    18. <div class="item col-4">4</div>
    19. <div class="item col-4">4</div>
    20. </div>
    21. <div class="row">
    22. <div class="item col-2">2</div>
    23. <div class="item col-8">8</div>
    24. <div class="item col-2">2</div>
    25. </div>
    26. <div class="row">
    27. <div class="item col-12">12</div>
    28. </div>
    29. </div>
    30. </body>
    31. </html>

    效果图:

    3. 仿实战项目首页布局

    • flex和grid搭配使用,实现大部分网页布局
    • 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="font_icon/iconfont.css" />
    8. <link rel="stylesheet" href="css/index.css" />
    9. </head>
    10. <body>
    11. <div class="head">
    12. <!-- 页眉 -->
    13. <header>
    14. <a href="">首页</a>
    15. <a href="">专题</a>
    16. <a href="">网站地图</a>
    17. <a href="">二手商品</a>
    18. <a href="">讨论区</a>
    19. <span>
    20. <a href=""><i class="iconfont icon-shouye"></i>登录</a>
    21. <a href="">注册</a>
    22. </span>
    23. </header>
    24. <!-- 搜索导航区 -->
    25. <section class="search-nav">
    26. <div class="logo-search">
    27. <a href=""><img src="images/logo.png" alt="logo" /></a>
    28. <div class="search">
    29. <input type="search" id="search" />
    30. <label for="search" class="iconfont icon-sousuo"></label>
    31. </div>
    32. <div class="tu">
    33. <a href="" class="iconfont icon-zan"></a>
    34. <a href="" class="iconfont icon-atm"></a>
    35. <a href="" class="iconfont icon-shangchuan"></a>
    36. <a href="" class="iconfont icon-yiliaohangyedeICON-"></a>
    37. <a href="" class="iconfont icon-huiyuan"></a>
    38. <a href="" class="iconfont icon-fangda"></a>
    39. </div>
    40. </div>
    41. <!-- 导航区 -->
    42. <nav>
    43. <div class="nav">
    44. <a href="" class="tubiao"><i class="iconfont icon-wendang1"></i></a>
    45. <a href="" class="a2">导航</a>
    46. <a href="">导航</a>
    47. <a href="">导航</a>
    48. <a href="">导航</a>
    49. <a href="">导航</a>
    50. <a href="" class="a2">导航</a>
    51. <a href="">导航</a>
    52. <a href="">导航</a>
    53. <a href="">导航</a>
    54. <a href="">导航</a>
    55. </div>
    56. <div class="nav">
    57. <a href="" class="tubiao"><i class="iconfont icon-wendang1"></i></a>
    58. <a href="" class="a2">导航</a>
    59. <a href="">导航</a>
    60. <a href="">导航</a>
    61. <a href="">导航</a>
    62. <a href="">导航</a>
    63. <a href="" class="a2">导航</a>
    64. <a href="">导航</a>
    65. <a href="">导航</a>
    66. <a href="">导航</a>
    67. <a href="">导航</a>
    68. </div>
    69. <div class="nav">
    70. <a href="" class="tubiao"><i class="iconfont icon-wendang1"></i></a>
    71. <a href="" class="a2">导航</a>
    72. <a href="">导航</a>
    73. <a href="">导航</a>
    74. <a href="">导航</a>
    75. <a href="">导航</a>
    76. <a href="" class="a2">导航</a>
    77. <a href="">导航</a>
    78. <a href="">导航</a>
    79. <a href="">导航</a>
    80. <a href="">导航</a>
    81. </div>
    82. <div class="nav">
    83. <a href="" class="tubiao"><i class="iconfont icon-wendang1"></i></a>
    84. <a href="" class="a2">导航</a>
    85. <a href="">导航</a>
    86. <a href="">导航</a>
    87. <a href="">导航</a>
    88. <a href="">导航</a>
    89. <a href="" class="a2">导航</a>
    90. <a href="">导航</a>
    91. <a href="">导航</a>
    92. <a href="">导航</a>
    93. <a href="">导航</a>
    94. </div>
    95. </nav>
    96. </section>
    97. <section class="tu-2">
    98. <a href=""><img src="images/2.jpg" alt="图1" /></a>
    99. <a href=""><img src="images/banner-right.jpg" alt="图2" /></a>
    100. </section>
    101. </div>
    102. <main>
    103. <h1 class="main-title"><span> 新闻资讯</span></h1>
    104. <div class="news">
    105. <div class="news-1">
    106. <a href=""><img src="images/news.jpg" alt="新闻图1" /> </a>
    107. <a href=""><img src="images/n-2.jpg" alt="新闻图2" /> </a>
    108. <a href="">图2说</a>
    109. <a href=""><img src="images/n-3.jpg" alt="新闻图3" /> </a>
    110. <a href="">图3说</a>
    111. </div>
    112. <div class="news-2">
    113. <a href="">新闻头条新闻头条新闻</a>
    114. <span>[新闻]</span>
    115. <span>[新闻]</span>
    116. <span>[新闻]</span>
    117. <span>[新闻]</span>
    118. <span></span>
    119. <span>[新闻]</span>
    120. <span>[新闻]</span>
    121. <span>[新闻]</span>
    122. <span>[新闻]</span>
    123. <span>[新闻]</span>
    124. <span>[新闻]</span>
    125. <a href="">新闻标题1</a>
    126. <a href="">新闻标题2</a>
    127. <a href="">新闻标题3</a>
    128. <a href="">新闻标题4</a>
    129. <a href=""></a>
    130. <a href="">新闻标题6</a>
    131. <a href="">新闻标题7</a>
    132. <a href="">新闻标题8</a>
    133. <a href="">新闻标题9</a>
    134. <a href="">新闻标题10</a>
    135. <a href="">新闻标题11</a>
    136. </div>
    137. <div class="news-2">
    138. <a href="">促销头条促销头条</a>
    139. <span>[促销]</span>
    140. <span>[促销]</span>
    141. <span>[促销]</span>
    142. <span>[促销]</span>
    143. <span></span>
    144. <span>[促销]</span>
    145. <span>[促销]</span>
    146. <span>[促销]</span>
    147. <span>[促销]</span>
    148. <span>[促销]</span>
    149. <span>[促销]</span>
    150. <a href="">促销标题1</a>
    151. <a href="">促销标题2</a>
    152. <a href="">促销标题3</a>
    153. <a href="">促销标题4</a>
    154. <a href=""></a>
    155. <a href="">促销标题6</a>
    156. <a href="">新闻标题7</a>
    157. <a href="">新闻标题8</a>
    158. <a href="">新闻标题9</a>
    159. <a href="">新闻标题10</a>
    160. <a href="">新闻标题11</a>
    161. </div>
    162. </div>
    163. <h1 class="main-title"><span> 图片专区</span></h1>
    164. <div class="photo">
    165. <div class="photo-area">
    166. <h2><a href="">美女</a><small>纵观艺术摄影</small></h2>
    167. <a href="">
    168. <img src="images/img2.jpg" alt="tu" />
    169. <span>愿你生活的都是每一天都是快快乐乐的</span>
    170. </a>
    171. <a href="">
    172. <img src="images/img2.jpg" alt="tu" />
    173. <span>愿你生活的都是每一天都是快快乐乐的</span>
    174. </a>
    175. <a href="">
    176. <img src="images/img2.jpg" alt="tu" />
    177. <span>愿你生活的都是每一天都是快快乐乐的</span>
    178. </a>
    179. <a href="">
    180. <img src="images/img2.jpg" alt="tu" />
    181. <span>愿你生活的都是每一天都是快快乐乐的</span>
    182. </a>
    183. </div>
    184. <div class="photo-area">
    185. <h2><a href="">美女</a><small>纵观艺术摄影</small></h2>
    186. <a href="">
    187. <img src="images/img2.jpg" alt="tu" />
    188. <span>愿你生活的都是每一天都是快快乐乐的</span>
    189. </a>
    190. <a href="">
    191. <img src="images/img2.jpg" alt="tu" />
    192. <span>愿你生活的都是每一天都是快快乐乐的</span>
    193. </a>
    194. <a href="">
    195. <img src="images/img2.jpg" alt="tu" />
    196. <span>愿你生活的都是每一天都是快快乐乐的</span>
    197. </a>
    198. <a href="">
    199. <img src="images/img2.jpg" alt="tu" />
    200. <span>愿你生活的都是每一天都是快快乐乐的</span>
    201. </a>
    202. </div>
    203. <div class="photo-area">
    204. <h2><a href="">美女</a><small>纵观艺术摄影</small></h2>
    205. <a href="">
    206. <img src="images/img2.jpg" alt="tu" />
    207. <span>愿你生活的都是每一天都是快快乐乐的</span>
    208. </a>
    209. <a href="">
    210. <img src="images/img2.jpg" alt="tu" />
    211. <span>愿你生活的都是每一天都是快快乐乐的</span>
    212. </a>
    213. <a href="">
    214. <img src="images/img2.jpg" alt="tu" />
    215. <span>愿你生活的都是每一天都是快快乐乐的</span>
    216. </a>
    217. <a href="">
    218. <img src="images/img2.jpg" alt="tu" />
    219. <span>愿你生活的都是每一天都是快快乐乐的</span>
    220. </a>
    221. </div>
    222. </div>
    223. <h1 class="main-title"><span> 二手市场</span></h1>
    224. <div class="forsale">
    225. <h2><a href="">抢好货</a><small>0低价, 便捷,安全,快速</small></h2>
    226. <div class="classify">
    227. <h2>热门分类</h2>
    228. <a href="">分类1</a>
    229. <a href="">分类2</a>
    230. <a href="">分类3</a>
    231. <a href="">分类4</a>
    232. <a href="">分类5</a>
    233. </div>
    234. <div class="hot">
    235. <div class="star">
    236. <div class="star-area">
    237. <a href=""><img src="images/shop5.jpg" alt="" /> </a>
    238. <a href=""
    239. ><img src="" alt="" />美女性感写真海报墙艺术装饰画贴画图</a
    240. >
    241. <p>
    242. <span class="price">¥ 453</span><span class="bj">写真</span>
    243. </p>
    244. </div>
    245. <div class="star-area">
    246. <a href=""><img src="images/shop5.jpg" alt="" /> </a>
    247. <a href=""
    248. ><img src="" alt="" />美女性感写真海报墙艺术装饰画贴画图</a
    249. >
    250. <p>
    251. <span class="price">¥ 453</span><span class="bj">写真</span>
    252. </p>
    253. </div>
    254. <div class="star-area">
    255. <a href=""><img src="images/shop5.jpg" alt="" /> </a>
    256. <a href=""
    257. ><img src="" alt="" />美女性感写真海报墙艺术装饰画贴画图</a
    258. >
    259. <p>
    260. <span class="price">¥ 453</span><span class="bj">写真</span>
    261. </p>
    262. </div>
    263. <div class="star-area">
    264. <a href=""><img src="images/shop5.jpg" alt="" /> </a>
    265. <a href=""
    266. ><img src="" alt="" />美女性感写真海报墙艺术装饰画贴画图</a
    267. >
    268. <p>
    269. <span class="price">¥ 453</span><span class="bj">写真</span>
    270. </p>
    271. </div>
    272. <div class="star-area">
    273. <a href=""><img src="images/shop5.jpg" alt="" /> </a>
    274. <a href=""
    275. ><img src="" alt="" />美女性感写真海报墙艺术装饰画贴画图</a
    276. >
    277. <p>
    278. <span class="price">¥ 453</span><span class="bj">写真</span>
    279. </p>
    280. </div>
    281. <div class="star-area">
    282. <a href=""><img src="images/shop5.jpg" alt="" /> </a>
    283. <a href=""
    284. ><img src="" alt="" />美女性感写真海报墙艺术装饰画贴画图</a
    285. >
    286. <p>
    287. <span class="price">¥ 453</span><span class="bj">写真</span>
    288. </p>
    289. </div>
    290. <div class="star-area">
    291. <a href=""><img src="images/shop5.jpg" alt="" /> </a>
    292. <a href=""
    293. ><img src="" alt="" />美女性感写真海报墙艺术装饰画贴画图</a
    294. >
    295. <p>
    296. <span class="price">¥ 453</span><span class="bj">写真</span>
    297. </p>
    298. </div>
    299. <div class="star-area">
    300. <a href=""><img src="images/shop5.jpg" alt="" /> </a>
    301. <a href=""
    302. ><img src="" alt="" />美女性感写真海报墙艺术装饰画贴画图</a
    303. >
    304. <p>
    305. <span class="price">¥ 453</span><span class="bj">写真</span>
    306. </p>
    307. </div>
    308. </div>
    309. <div class="other">
    310. <a href=""><img src="images/1.png" alt="" /> </a>
    311. <a href=""><img src="images/1.png" alt="" /></a>
    312. <a href=""><img src="images/1.png" alt="" /></a>
    313. <a href=""><img src="images/1.png" alt="" /></a>
    314. <a class="gg" href=""><img src="images/11.png" alt="" /></a>
    315. <a class="gg" href=""><img src="images/12.jpg" alt="" /></a>
    316. </div>
    317. </div>
    318. </div>
    319. <h1 class="main-title"><span> 合作单位</span></h1>
    320. </main>
    321. <footer>
    322. <div class="cooperation">
    323. <a href="">php中文网1</a>
    324. <a href="">php中文网2</a>
    325. <a href="">php中文网3</a>
    326. <a href="">php中文网4</a>
    327. <a href="">php中文网5</a>
    328. <a href="">php中文网6</a>
    329. <a href="">php中文网7</a>
    330. <a href="">php中文网8</a>
    331. <a href="">php中文网9</a>
    332. <a href="">php中文网10</a>
    333. <a href="">php中文网11</a>
    334. <a href="">php中文网12</a>
    335. <a href="">php中文网13</a>
    336. <a href="">php中文网14</a>
    337. <a href="">php中文网15</a>
    338. </div>
    339. <div class="foot">
    340. <div class="information">
    341. <div class="foot-nav">
    342. <a href="">导航1</a>
    343. <a href="">导航2</a>
    344. <a href="">导航3</a>
    345. <a href="">导航4</a>
    346. <a href="">导航5</a>
    347. <a href="">导航6</a>
    348. </div>
    349. <div class="info">
    350. <h1>LOGO</h1>
    351. <p>
    352. 2019 fengniao.com. All rights reserved .
    353. 安徽闹着玩有限公司(无聊网)版权所有
    354. </p>
    355. <p>
    356. 皖ICP证150110号 京ICP备14323013号-2 皖公网安备110108024357788号
    357. </p>
    358. <p>
    359. 违法和不良信息举报电话: 0551-1234567 举报邮箱: admin@baidu.com
    360. </p>
    361. </div>
    362. </div>
    363. <div class="official">
    364. <label for="">关注公众号</label>
    365. <img src="images/code.png" alt="" />
    366. </div>
    367. </div>
    368. </footer>
    369. </body>
    370. </html>
    • css源码
  1. /* 通用样式 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. body {
  8. display: flex;
  9. flex-flow: column nowrap;
  10. min-width: 1120px;
  11. align-items: center;
  12. font-size: 14px;
  13. width: 100vw;
  14. background-color: #eee;
  15. }
  16. a {
  17. text-decoration: none;
  18. }
  19. .head {
  20. width: 100%;
  21. height: 520px;
  22. display: flex;
  23. flex-flow: column nowrap;
  24. align-items: center;
  25. background-color: #fff;
  26. }
  27. /* 页眉 */
  28. header {
  29. width: 100%;
  30. height: 50px;
  31. background-color: rgb(10, 0, 0);
  32. display: flex;
  33. align-items: center;
  34. padding: 0 20px;
  35. }
  36. header > a {
  37. color: rgb(236, 217, 217);
  38. line-height: 50px;
  39. padding: 0 10px;
  40. }
  41. header > a:hover {
  42. color: yellow;
  43. }
  44. header > span {
  45. line-height: 50px;
  46. margin-left: auto;
  47. }
  48. header > span * {
  49. padding: 0 10px;
  50. }
  51. /* 搜索区
  52. */
  53. .logo-search {
  54. display: flex;
  55. flex-flow: row nowrap;
  56. width: 100%;
  57. height: 60px;
  58. display: flex;
  59. flex-flow: row nowrap;
  60. justify-content: space-between;
  61. align-items: center;
  62. margin-top: 20px;
  63. }
  64. .search {
  65. display: flex;
  66. flex-flow: row nowrap;
  67. align-items: center;
  68. position: relative;
  69. left: 10vw;
  70. }
  71. .search > input {
  72. border-radius: 10px;
  73. width: 30vw;
  74. height: 40px;
  75. }
  76. .search > label {
  77. font-size: 25px;
  78. position: relative;
  79. top: 5px;
  80. left: -33px;
  81. }
  82. .logo-search > .tu {
  83. display: flex;
  84. flex-flow: row nowrap;
  85. align-items: center;
  86. }
  87. .logo-search > .tu > a {
  88. padding: 0 5px;
  89. font-size: 40px;
  90. align-self: start;
  91. color: #000;
  92. }
  93. .logo-search img {
  94. height: 60px;
  95. width: 10vw;
  96. }
  97. /* 导航区 */
  98. .search-nav {
  99. width: 80%;
  100. display: flex;
  101. flex-flow: column nowrap;
  102. align-items: center;
  103. }
  104. nav {
  105. width: 100%;
  106. height: 50px;
  107. display: flex;
  108. flex-flow: row nowrap;
  109. align-items: center;
  110. margin-top: 20px;
  111. }
  112. nav > .nav {
  113. width: 25%;
  114. display: grid;
  115. grid-template-columns: repeat(6, minmax(30px, auto));
  116. grid-template-rows: repeat(2, 1fr);
  117. justify-content: start;
  118. justify-items: center;
  119. align-items: center;
  120. }
  121. nav > .nav > a {
  122. padding: 0 4px;
  123. display: flex;
  124. flex-flow: row nowrap;
  125. }
  126. nav > .nav > .tubiao {
  127. grid-row-start: span 2;
  128. }
  129. nav > .nav > .a2 {
  130. border-right: 1px solid #ccc;
  131. padding-right: 5px;
  132. }
  133. nav > .nav i {
  134. font-size: 50px;
  135. font-stretch: wider;
  136. }
  137. .head > .tu-2 {
  138. margin-top: 20px;
  139. width: 80%;
  140. height: 250px;
  141. display: grid;
  142. gap: 5px;
  143. grid-template-columns: 3fr 1fr;
  144. /* justify-items: center; */
  145. }
  146. .head > .tu-2 img {
  147. width: 100%;
  148. height: 260px;
  149. }
  150. /* 主体区 */
  151. main {
  152. display: flex;
  153. flex-flow: column nowrap;
  154. margin-top: 20px;
  155. width: 80%;
  156. }
  157. main > * {
  158. margin-top: 20px;
  159. }
  160. .main-title {
  161. text-align: center;
  162. }
  163. .main-title > span {
  164. padding-bottom: 8px;
  165. color: darkslategrey;
  166. border-bottom: 3px solid seagreen;
  167. }
  168. .news {
  169. width: 100%;
  170. height: 380px;
  171. background-color: #fff;
  172. display: grid;
  173. grid-template-columns: repeat(3, 1fr);
  174. /* grid-template-rows: minmax(auto, 320px); */
  175. padding: 30px 15px;
  176. }
  177. .news > .news-1 {
  178. height: 320px;
  179. display: grid;
  180. grid-template-columns: repeat(2, 1fr);
  181. grid-template-rows: 50% 40% 10%;
  182. justify-items: center;
  183. gap: 10px;
  184. grid-template-areas:
  185. "news-top news-top"
  186. "mid-lfet mid-right"
  187. "bottom-left bottom-right";
  188. }
  189. .news > .news-1 > a:nth-of-type(1) {
  190. grid-area: news-top;
  191. }
  192. .news > .news-1 > a:nth-of-type(2) {
  193. grid-area: mid-lfet;
  194. }
  195. .news > .news-1 > a:nth-of-type(3) {
  196. grid-area: bottom-left;
  197. }
  198. .news > .news-1 > a:nth-of-type(4) {
  199. grid-area: mid-right;
  200. }
  201. .news > .news-1 > a:nth-of-type(5) {
  202. grid-area: bottom-right;
  203. }
  204. .news a {
  205. width: 100%;
  206. }
  207. .news img {
  208. width: 100%;
  209. height: 100%;
  210. }
  211. .news-2 {
  212. display: grid;
  213. grid-template-columns: 2fr 7fr;
  214. grid-template-rows: repeat(12, 1fr);
  215. align-items: center;
  216. grid-auto-flow: column;
  217. padding: 0 20px;
  218. }
  219. .news-2 span {
  220. color: rgb(59, 54, 54);
  221. min-width: 30px;
  222. display: flex;
  223. flex-flow: row nowrap;
  224. }
  225. .news-2 > a:first-of-type {
  226. display: flex;
  227. flex-flow: row nowrap;
  228. grid-column-end: span 2;
  229. font-size: 1.2rem;
  230. color: rgb(180, 78, 78);
  231. }
  232. .photo {
  233. width: 100%;
  234. display: flex;
  235. flex-flow: row nowrap;
  236. justify-content: space-between;
  237. }
  238. .photo > .photo-area {
  239. width: 32%;
  240. height: 420px;
  241. background-color: #fff;
  242. padding: 15px;
  243. border-radius: 15px;
  244. display: grid;
  245. grid-template-columns: repeat(2, 1fr);
  246. grid-template-rows: 1fr 3fr 3fr;
  247. gap: 5px;
  248. align-items: center;
  249. }
  250. .photo > .photo-area > h2 {
  251. width: 100%;
  252. grid-column-end: span 2;
  253. border-bottom: 1px solid red;
  254. padding-bottom: 10px;
  255. }
  256. .photo > .photo-area > h2 > small {
  257. font-size: 0.6em;
  258. color: brown;
  259. margin-left: 10px;
  260. }
  261. .photo > .photo-area > a {
  262. width: 100%;
  263. }
  264. .photo > .photo-area span {
  265. font-size: 0.9em;
  266. color: rgb(22, 17, 17);
  267. }
  268. .photo > .photo-area img {
  269. width: 100%;
  270. }
  271. .forsale {
  272. width: 100%;
  273. height: 600px;
  274. display: flex;
  275. flex-flow: column nowrap;
  276. background-color: #fff;
  277. border-radius: 15px;
  278. padding: 20px 10px;
  279. }
  280. .forsale > h2 {
  281. padding-bottom: 15px;
  282. border-bottom: 1px solid lightcoral;
  283. }
  284. .forsale > h2 > a {
  285. color: rgb(92, 68, 68);
  286. }
  287. .forsale > h2 > small {
  288. font-size: 0.6em;
  289. color: brown;
  290. margin-left: 10px;
  291. }
  292. .classify {
  293. display: flex;
  294. flex-flow: row nowrap;
  295. align-items: flex-end;
  296. }
  297. .classify > * {
  298. margin-right: 20px;
  299. }
  300. .classify > h2 {
  301. color: red;
  302. }
  303. .hot {
  304. width: 100%;
  305. margin-top: 20px;
  306. display: flex;
  307. flex-flow: row nowrap;
  308. justify-content: space-between;
  309. }
  310. .star {
  311. width: 56%;
  312. padding: 10px 0;
  313. display: grid;
  314. grid-template-rows: 50% 50%;
  315. grid-template-columns: repeat(4, 25%);
  316. gap: 5px;
  317. }
  318. .star-area {
  319. width: 100%;
  320. display: flex;
  321. flex-flow: column nowrap;
  322. }
  323. .star-area > p {
  324. display: flex;
  325. flex-flow: row nowrap;
  326. justify-content: space-between;
  327. }
  328. .star-area > a {
  329. width: 100%;
  330. }
  331. .star-area img {
  332. width: 100%;
  333. max-height: 140px;
  334. border-radius: 10px;
  335. }
  336. .other {
  337. width: 40%;
  338. display: grid;
  339. grid-template-rows: 2fr 2fr 1fr 1fr;
  340. grid-template-columns: 1fr 1fr;
  341. gap: 5px;
  342. }
  343. .other > a {
  344. width: 100%;
  345. }
  346. .other > a > img {
  347. max-height: 150px;
  348. width: 100%;
  349. }
  350. .other > .gg {
  351. grid-column-end: span 2;
  352. }
  353. .other > .gg > img {
  354. max-height: 70px;
  355. }
  356. footer {
  357. margin-top: 30px;
  358. width: 100%;
  359. height: 500px;
  360. background-color: #fff;
  361. display: flex;
  362. flex-flow: column nowrap;
  363. align-items: center;
  364. }
  365. .cooperation {
  366. height: 200px;
  367. padding-top: 20px;
  368. display: grid;
  369. grid-template-columns: repeat(12, 1fr);
  370. grid-template-rows: 1fr 1fr;
  371. gap: 10px;
  372. align-items: center;
  373. }
  374. .cooperation > a {
  375. padding: 5px;
  376. color: #000;
  377. }
  378. .foot {
  379. width: 100%;
  380. height: 300px;
  381. background-color: rgb(22, 11, 11);
  382. display: flex;
  383. flex-flow: row nowrap;
  384. justify-content: space-evenly;
  385. padding: 20px 70px;
  386. }
  387. .information {
  388. display: flex;
  389. flex-flow: column nowrap;
  390. justify-content: space-around;
  391. width: 60%;
  392. }
  393. .foot-nav {
  394. display: flex;
  395. flex-flow: row nowrap;
  396. }
  397. .foot-nav > a {
  398. padding: 10px;
  399. color: rgb(231, 212, 212);
  400. }
  401. .information > .info {
  402. display: grid;
  403. grid-template-columns: 1fr 4fr;
  404. grid-template-rows: 1fr 1fr 1fr;
  405. align-items: center;
  406. gap: 30px;
  407. }
  408. .information > .info > p {
  409. color: rgb(231, 212, 212);
  410. }
  411. .information > .info > h1 {
  412. grid-row-end: span 3;
  413. color: rgb(231, 212, 212);
  414. }
  415. .official {
  416. border-left: 1px solid rgb(180, 78, 78);
  417. display: flex;
  418. flex-flow: column nowrap;
  419. align-items: center;
  420. padding-left: 20px;
  421. }
  422. .official > label {
  423. color: rgb(231, 212, 212);
  424. }
  425. .official > img {
  426. width: 120px;
  427. height: 120px;
  428. }

效果图:

4. 总结

  • grid和flex配合使用可以实现大部分的网页布局功能
  • 复杂的网页布局中提前做好页面规划非常重要
  • 容器的宽高如果不是固定值,要注意内容是否溢出
上一条:Grid 布局下一条:php环境与变量
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议