博客列表 >grid整站布局

grid整站布局

王娇
王娇原创
2020年04月28日 16:15:40870浏览

学习总结

  • grid主要适用于布局大框架,而细节处理还是需要grid和flex配合进行
  • 使用grid可以简化html和css文件中的代码量
  • 下面代码还可以优化,二手交易在是用flex布局,可以用grid布局

    1.仿整站首页

  • 演示链接 仿老师的整站首页
  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. <link rel="stylesheet" href="../static/font/iconfont.css" />
  7. <link rel="stylesheet" href="index.css" />
  8. <title>全站首页</title>
  9. </head>
  10. <body>
  11. <!-- 全站页眉 -->
  12. <div class="public_header">
  13. <a href="">网站首页</a>
  14. <a href="">专题</a>
  15. <a href="">网站导航</a>
  16. <a href="">二手商品</a>
  17. <a href="">讨论区</a>
  18. <span>
  19. <a href=""><label class="iconfont icon-huiyuan2"></label>登陆</a>
  20. <a href="">免费注册</a>
  21. </span>
  22. </div>
  23. <!-- 首页快速进入按钮、轮播图、搜索框 -->
  24. <div class="index_header">
  25. <div class="logo_search">
  26. <!-- logo图标 -->
  27. <div>
  28. <a href=""><img src="../static/images/logo.png" alt="" /></a>
  29. </div>
  30. <!-- 搜索框 -->
  31. <div>
  32. <input type="search" name="search" id="search" />
  33. <label for="search" class="iconfont icon-sousuo1"></label>
  34. </div>
  35. <!-- 字体图标 点赞 评论 下载 会员等 -->
  36. <div>
  37. <span class="iconfont icon-huiyuan1"></span>
  38. <span class="iconfont icon-danmu1"></span>
  39. <span class="iconfont icon-fabu"></span>
  40. <span class="iconfont con-fangda"></span>
  41. <span class="iconfont icon-huiyuan2"></span>
  42. <span class="iconfont icon-dianzan"></span>
  43. </div>
  44. </div>
  45. <div class="nav">
  46. <div class="detail">
  47. <div>
  48. <span class="iconfont icon-gongdan"></span>
  49. </div>
  50. <div>
  51. <p>资讯</p>
  52. <p>学习</p>
  53. </div>
  54. <div>
  55. <a href="">器材</a>
  56. <a href="">大师</a>
  57. <a href="">实战</a>
  58. <a href="">大赛</a>
  59. <a href="">其它</a>
  60. <a href="">器材</a>
  61. <a href="">器材</a>
  62. <a href="">器材</a>
  63. </div>
  64. </div>
  65. <div class="detail">
  66. <div>
  67. <span class="iconfont icon-renwujincheng"></span>
  68. </div>
  69. <div>
  70. <p>资讯</p>
  71. <p>学习</p>
  72. </div>
  73. <div>
  74. <a href="">器材</a>
  75. <a href="">大师</a>
  76. <a href="">实战</a>
  77. <a href="">大赛</a>
  78. <a href="">其它</a>
  79. <a href="">器材</a>
  80. <a href="">器材</a>
  81. <a href="">器材</a>
  82. </div>
  83. </div>
  84. <div class="detail">
  85. <div>
  86. <span class="iconfont icon-gongdan"></span>
  87. </div>
  88. <div>
  89. <p>资讯</p>
  90. <p>学习</p>
  91. </div>
  92. <div>
  93. <a href="">器材</a>
  94. <a href="">大师</a>
  95. <a href="">实战</a>
  96. <a href="">大赛</a>
  97. <a href="">其它</a>
  98. <a href="">器材</a>
  99. <a href="">器材</a>
  100. <a href="">器材</a>
  101. </div>
  102. </div>
  103. <div class="detail">
  104. <div>
  105. <span class="iconfont icon-DOC"></span>
  106. </div>
  107. <div>
  108. <p>资讯</p>
  109. <p>学习</p>
  110. </div>
  111. <div>
  112. <a href="">器材</a>
  113. <a href="">大师</a>
  114. <a href="">实战</a>
  115. <a href="">大赛</a>
  116. <a href="">其它</a>
  117. <a href="">器材</a>
  118. <a href="">器材</a>
  119. <a href="">器材</a>
  120. </div>
  121. </div>
  122. </div>
  123. <div class="lunbo">
  124. <div>
  125. <a href=""><img src="../static/images/4.jpg" alt="" /></a>
  126. </div>
  127. <div>
  128. <a href=""><img src="../static/images/banner-right.jpg" alt="" /></a>
  129. </div>
  130. </div>
  131. </div>
  132. <!-- 新闻资讯 -->
  133. <div class="indexTitle">
  134. <h1>新闻资讯</h1>
  135. </div>
  136. <div class="indexArticle">
  137. <!-- 新闻大图 -->
  138. <div>
  139. <a href=""><img src="../static/images/news.jpg" alt="" /></a>
  140. </div>
  141. <!-- 两个促销商品小图 -->
  142. <div>
  143. <div>
  144. <a href=""><img src="../static/images/n-2.jpg" alt="" /></a>
  145. <a href="">三星note10发布搭载挖孔前摄</a>
  146. </div>
  147. <div>
  148. <a href=""><img src="../static/images/n-3.jpg" alt="" /></a>
  149. <a href="">小米公布1亿像素手机信息</a>
  150. </div>
  151. </div>
  152. <!-- 新闻链接 -->
  153. <div>
  154. <p>大隐于市的摄影师,薇薇安·迈尔!</p>
  155. <div>
  156. <span>[新闻]</span>
  157. <a href="">佳能 EOS RP 12899元起</a>
  158. </div>
  159. <div>
  160. <span>[新闻]</span>
  161. <a href="">定焦,变焦, 新人小白如何选择?这三款值得买</a>
  162. </div>
  163. <div>
  164. <span>[新闻]</span>
  165. <a href="">新一代入门神器? 佳能EOS 850D将到来</a>
  166. </div>
  167. <div>
  168. <span>[新闻]</span>
  169. <a href="">无低通次旗舰 D7500套机6899元</a>
  170. </div>
  171. </div>
  172. <div>
  173. <div>
  174. <span>[新闻]</span>
  175. <a href="">佳能注册相机无线充电和眼控对焦专利</a>
  176. </div>
  177. <div>
  178. <span>[新闻]</span>
  179. <a href="">复古全幅单反 尼康Df套机14500元</a>
  180. </div>
  181. <div>
  182. <span>[新闻]</span>
  183. <a href="">索尼α7R IV超广套装售42698元</a>
  184. </div>
  185. <div>
  186. <span>[新闻]</span>
  187. <a href="">RF大三元长焦 RF70-200mm售17699</a>
  188. </div>
  189. <div>
  190. <span>[新闻]</span>
  191. <a href="">有所保留 佳能EOS-1D X III再曝新功能</a>
  192. </div>
  193. </div>
  194. <!-- 促销链接 -->
  195. <div>
  196. <p>元旦,春节双节联动,备货啦!</p>
  197. <div>
  198. <span>[促销]</span>
  199. <a href="">佳能 EOS RP 12899元起</a>
  200. </div>
  201. <div>
  202. <span>[促销]</span>
  203. <a href="">定焦,变焦, 新人小白如何选择?这三款值得买</a>
  204. </div>
  205. <div>
  206. <span>[促销]</span>
  207. <a href="">新一代入门神器? 佳能EOS 850D将到来</a>
  208. </div>
  209. <div>
  210. <span>[促销]</span>
  211. <a href="">无低通次旗舰 D7500套机6899元</a>
  212. </div>
  213. </div>
  214. <div>
  215. <div>
  216. <span>[促销]</span>
  217. <a href="">佳能注册相机无线充电和眼控对焦专利</a>
  218. </div>
  219. <div>
  220. <span>[促销]</span>
  221. <a href="">复古全幅单反 尼康Df套机14500元</a>
  222. </div>
  223. <div>
  224. <span>[促销]</span>
  225. <a href="">索尼α7R IV超广套装售42698元</a>
  226. </div>
  227. <div>
  228. <span>[促销]</span>
  229. <a href="">RF大三元长焦 RF70-200mm售17699</a>
  230. </div>
  231. <div>
  232. <span>[促销]</span>
  233. <a href="">有所保留 佳能EOS-1D X III再曝新功能</a>
  234. </div>
  235. </div>
  236. </div>
  237. <!-- 图片专区 -->
  238. <div class="indexTitle">
  239. <h1>图片专区</h1>
  240. </div>
  241. <div class="indexPicture">
  242. <div class="picture">
  243. <div>
  244. <a href="">美女</a>
  245. <span>纵观摄影艺术</span>
  246. </div>
  247. <div>
  248. <div>
  249. <a href=""><img src="../static/images/img1.jpg" alt="" /></a>
  250. <a href="">阴沉夏日的柔美身姿 复古少女的藕荷色心情</a>
  251. </div>
  252. <div>
  253. <a href=""><img src="../static/images/img2.jpg" alt="" /></a>
  254. <a href="">愿你生活的都是每一天都是快快乐乐的, 一定要</a>
  255. </div>
  256. <div>
  257. <a href=""><img src="../static/images/img3.jpg" alt="" /></a>
  258. <a href="">今夜我不关心人类,我只想你,从爱上你的那天起</a>
  259. </div>
  260. <div>
  261. <a href=""><img src="../static/images/img4.jpg" alt="" /></a>
  262. <a href="">我转头,看见你走来,在阳光里,于是笑容从我心里溢出</a>
  263. </div>
  264. </div>
  265. </div>
  266. <div class="picture">
  267. <div>
  268. <a href="">健康</a>
  269. <span>纵观摄影艺术</span>
  270. </div>
  271. <div>
  272. <div>
  273. <a href=""><img src="../static/images/img1.jpg" alt="" /></a>
  274. <a href="">阴沉夏日的柔美身姿 复古少女的藕荷色心情</a>
  275. </div>
  276. <div>
  277. <a href=""><img src="../static/images/img3.jpg" alt="" /></a>
  278. <a href="">愿你生活的都是每一天都是快快乐乐的, 一定要</a>
  279. </div>
  280. <div>
  281. <a href=""><img src="../static/images/img4.jpg" alt="" /></a>
  282. <a href="">今夜我不关心人类,我只想你,从爱上你的那天起</a>
  283. </div>
  284. <div>
  285. <a href=""><img src="../static/images/img5.jpg" alt="" /></a>
  286. <a href="">我转头,看见你走来,在阳光里,于是笑容从我心里溢出</a>
  287. </div>
  288. </div>
  289. </div>
  290. <div class="picture">
  291. <div>
  292. <a href="">青春</a>
  293. <span>纵观摄影艺术</span>
  294. </div>
  295. <div>
  296. <div>
  297. <a href=""><img src="../static/images/img5.jpg" alt="" /></a>
  298. <a href="">阴沉夏日的柔美身姿 复古少女的藕荷色心情</a>
  299. </div>
  300. <div>
  301. <a href=""><img src="../static/images/img3.jpg" alt="" /></a>
  302. <a href="">愿你生活的都是每一天都是快快乐乐的, 一定要</a>
  303. </div>
  304. <div>
  305. <a href=""><img src="../static/images/img2.jpg" alt="" /></a>
  306. <a href="">今夜我不关心人类,我只想你,从爱上你的那天起</a>
  307. </div>
  308. <div>
  309. <a href=""><img src="../static/images/img1.jpg" alt="" /></a>
  310. <a href="">我转头,看见你走来,在阳光里,于是笑容从我心里溢出</a>
  311. </div>
  312. </div>
  313. </div>
  314. </div>
  315. <!-- 二手交易 -->
  316. <div class="indexTitle">
  317. <h1>二手交易</h1>
  318. </div>
  319. <div class="indexShop">
  320. <div>
  321. <a href="">抢好货</a>
  322. <span>0低价, 便捷,安全,快速</span>
  323. </div>
  324. <div>
  325. <span>热门分类</span>
  326. <a href="">美女写真</a>
  327. <a href="">日本美女</a>
  328. <a href="">美国美女</a>
  329. <a href="">国内美女</a>
  330. <a href="">AV美女</a>
  331. </div>
  332. <div>
  333. <div class="commList">
  334. <div>
  335. <div>
  336. <a href=""
  337. ><img src="../static/images/shop/shop1.jpg" alt=""
  338. /></a>
  339. </div>
  340. <a href="">美女写真墙上装饰贴画快感艺术海报</a>
  341. <div>
  342. <span>¥345</span>
  343. <span>美女</span>
  344. </div>
  345. </div>
  346. <div>
  347. <div>
  348. <a href=""
  349. ><img src="../static/images/shop/shop2.jpg" alt=""
  350. /></a>
  351. </div>
  352. <a href="">美女写真墙上装饰贴画快感艺术海报</a>
  353. <div>
  354. <span>¥345</span>
  355. <span>素颜</span>
  356. </div>
  357. </div>
  358. <div>
  359. <div>
  360. <a href=""
  361. ><img src="../static/images/shop/shop3.jpg" alt=""
  362. /></a>
  363. </div>
  364. <a href="">美女写真墙上装饰贴画快感艺术海报</a>
  365. <div>
  366. <span>¥345</span>
  367. <span>大学生</span>
  368. </div>
  369. </div>
  370. <div>
  371. <div>
  372. <a href=""
  373. ><img src="../static/images/shop/shop4.jpg" alt=""
  374. /></a>
  375. </div>
  376. <a href="">美女写真墙上装饰贴画快感艺术海报</a>
  377. <div>
  378. <span>¥345</span>
  379. <span>美女</span>
  380. </div>
  381. </div>
  382. <div>
  383. <div>
  384. <a href=""
  385. ><img src="../static/images/shop/shop5.jpg" alt=""
  386. /></a>
  387. </div>
  388. <a href="">美女写真墙上装饰贴画快感艺术海报</a>
  389. <div>
  390. <span>¥345</span>
  391. <span>美女</span>
  392. </div>
  393. </div>
  394. <div>
  395. <div>
  396. <a href=""
  397. ><img src="../static/images/shop/shop6.jpg" alt=""
  398. /></a>
  399. </div>
  400. <a href="">美女写真墙上装饰贴画快感艺术海报</a>
  401. <div>
  402. <span>¥345</span>
  403. <span>美女</span>
  404. </div>
  405. </div>
  406. <div>
  407. <div>
  408. <a href=""
  409. ><img src="../static/images/shop/shop7.jpg" alt=""
  410. /></a>
  411. </div>
  412. <a href="">美女写真墙上装饰贴画快感艺术海报</a>
  413. <div>
  414. <span>¥345</span>
  415. <span>美女</span>
  416. </div>
  417. </div>
  418. <div>
  419. <div>
  420. <a href=""
  421. ><img src="../static/images/shop/shop8.jpg" alt=""
  422. /></a>
  423. </div>
  424. <a href="">美女写真墙上装饰贴画快感艺术海报</a>
  425. <div>
  426. <span>¥345</span>
  427. <span>美女</span>
  428. </div>
  429. </div>
  430. </div>
  431. <div class="commClass">
  432. <a href=""><img src="../static/images/ad/1.png" alt="" /></a>
  433. <a href=""><img src="../static/images/ad/2.png" alt="" /></a>
  434. <a href=""><img src="../static/images/ad/3.png" alt="" /></a>
  435. <a href=""><img src="../static/images/ad/4.png" alt="" /></a>
  436. <a href=""><img src="../static/images/ad/image.png" alt="" /></a>
  437. <a href=""><img src="../static/images/ad/ad2.jpg" alt="" /></a>
  438. </div>
  439. </div>
  440. </div>
  441. <!-- 合作单位 -->
  442. <div class="indexTitle">
  443. <h1>合作单位</h1>
  444. </div>
  445. <div class="work_link">
  446. <div>
  447. <a href="">html合作单位</a>
  448. </div>
  449. <div>
  450. <a href="">python合作单位</a>
  451. </div>
  452. <div>
  453. <a href="">css合作单位</a>
  454. </div>
  455. <div>
  456. <a href="">php合作单位</a>
  457. </div>
  458. <div>
  459. <a href="">javascript合作单位</a>
  460. </div>
  461. <div>
  462. <a href="">javascript合作单位</a>
  463. </div>
  464. <div>
  465. <a href="">javascript合作单位</a>
  466. </div>
  467. <div>
  468. <a href="">javascript合作单位</a>
  469. </div>
  470. <div>
  471. <a href="">javascript合作单位</a>
  472. </div>
  473. <div>
  474. <a href="">javascript合作单位</a>
  475. </div>
  476. <div>
  477. <a href="">javascript合作单位</a>
  478. </div>
  479. <div>
  480. <a href="">javascript合作单位</a>
  481. </div>
  482. </div>
  483. <!-- 全站页脚 -->
  484. <div class="public_footer">
  485. <div class="footer_nav">
  486. <a href="">首页</a>
  487. <a href="">联系我们</a>
  488. <a href="">招聘信息</a>
  489. <a href="">友情链接</a>
  490. <a href="">用户服务协议</a>
  491. <a href="">隐私权声明</a>
  492. <a href="">法律投诉声明</a>
  493. </div>
  494. <div class="footer_logo">
  495. <img src="../static/images/logo.png" alt="" />
  496. </div>
  497. <div class="footer_info">
  498. <p>
  499. 2019 fengniao.com. All rights
  500. reserved.安徽闹着玩有限公司(无聊网)版权所有
  501. </p>
  502. <p>皖ICP证150110号 京ICP备14323013号-2 皖公网安备110108024357788号</p>
  503. <p>
  504. 违法和不良信息举报电话:
  505. <a href="tel:0551-1234567">0551-1234567</a> 举报邮箱:
  506. <a href="mailto:admin@baidu.com">admin@baidu.com</a>
  507. </p>
  508. </div>
  509. <div class="footer_ewm">
  510. <p>关注公众号</p>
  511. <img src="../static/images/erwei-code.png" alt="" />
  512. </div>
  513. </div>
  514. </body>
  515. </html>
  • css示例代码
  1. /* 引入全站公共清除样式 */
  2. @import "../static/css/reset.css";
  3. /* 引入全站头部导航 */
  4. @import "../components/public/publicHander/publicHander.css";
  5. /* 引入全站首页导航、搜索框、轮播图、快速进入按钮 */
  6. @import "../components/index/indexHeader/indexHeader.css";
  7. /* 引入首页大标题样式 */
  8. @import "../components/index/indexTitle/indexTitle.css";
  9. /* 引入首页新闻资讯模块样式 */
  10. @import "../components/article/index_article.css";
  11. /* 引入首页图片库模块样式 */
  12. @import "../components/picture/index_picture.css";
  13. /* 引入首页二手交易模块样式 */
  14. @import "../components/shop/index_shop.css";
  15. /* 引入首页合作单位模块样式 */
  16. @import "../components/index/indexLink/indexLink.css";
  17. /* 引入全站尾部导航 */
  18. @import "../components/public/publicFooter/publicFooter.css";
  19. /* 引入全站公共清除样式 reset.css*/
  20. * {
  21. margin: 0;
  22. padding: 0;
  23. box-sizing: border-box;
  24. font-size: 15px;
  25. }
  26. a {
  27. text-decoration: none;
  28. color: #555;
  29. }
  30. a:hover {
  31. color: red;
  32. }
  33. li {
  34. list-style-type: none;
  35. }
  36. /* 全站头部导航 publicHander.css*/
  37. /* 导入样式重置文件 */
  38. @import "../public_reset.css";
  39. /* 全站页眉样式 */
  40. .public_header {
  41. /* 导航定义为弹性布局 */
  42. display: flex;
  43. flex-flow: row nowrap;
  44. align-items: center;
  45. /* 基本样式 */
  46. background-color: lightgreen;
  47. height: 45px;
  48. padding: 0px 20px;
  49. }
  50. /* 基本导航左对齐 */
  51. .public_header a {
  52. color: black;
  53. padding: 13px 15px;
  54. }
  55. .public_header a:hover {
  56. color: white;
  57. background-color: blanchedalmond;
  58. }
  59. /* 登录和注册右对齐 */
  60. .public_header > span {
  61. margin-left: auto;
  62. }
  63. .public_header > span > a:hover {
  64. background-color: lightgreen;
  65. }
  66. /* 定义登录字体图标样式 */
  67. .public_header > span > a > label {
  68. font-size: 18px;
  69. padding: 0px 15px;
  70. }
  71. /* 全站页脚 publicFooter.css*/
  72. @import "../public_reset.css";
  73. /* 公共页脚样式,按网格显示 */
  74. .public_footer {
  75. /* 基本样式 */
  76. height: 260px;
  77. background-color: lightgreen;
  78. /* 页脚样式定义为网格布局 */
  79. display: grid;
  80. grid-template-columns: 150px 580px 400px; /*定义一个3列2行的网格*/
  81. grid-template-rows: 70px 140px;
  82. /* 通过网格区域名称来填充网格 */
  83. grid-template-areas:
  84. "footer_nav footer_nav footer_ewm"
  85. "footer_logo footer_info footer_ewm";
  86. /* 风格内容横向和纵向都居中对齐 */
  87. align-content: center;
  88. justify-content: center;
  89. }
  90. /* 页脚导航样式 */
  91. .footer_nav {
  92. grid-area: footer_nav; /*设置导航内容的区域化名称*/
  93. }
  94. .footer_nav > a {
  95. padding: 0px 15px;
  96. color: black;
  97. }
  98. .footer_nav > a:hover {
  99. color: white;
  100. }
  101. /* 网站logo样式 */
  102. .footer_logo {
  103. width: 160px;
  104. height: 76px;
  105. grid-area: footer_logo; /*设置logo区域化名称*/
  106. }
  107. /* 网站logo的图片大小自适应 */
  108. .footer_logo > img {
  109. max-width: 100%;
  110. max-height: 100%;
  111. }
  112. /* 网站备案内容样式 */
  113. .footer_info {
  114. grid-area: footer_info; /*设置网站备案内容区域化名称*/
  115. line-height: 40px;
  116. padding-left: 20px;
  117. }
  118. /* 二维码样式 */
  119. .footer_ewm {
  120. grid-area: footer_ewm; /*设置二维码区域化名称*/
  121. padding-left: 30px;
  122. border-left: 2px solid black;
  123. /* 设置二维码图标为弹性布局,主轴方向为列,不换行 */
  124. display: flex;
  125. flex-flow: column nowrap;
  126. }
  127. .footer_ewm > p {
  128. text-align: center;
  129. width: 100px;
  130. }
  131. /* 设置二维码图片的宽度和高度 */
  132. .footer_ewm > img {
  133. width: 110px;
  134. height: 110px;
  135. margin-top: 10px;
  136. }
  137. /* 首页导航,轮播图 搜索框 indexHeader.css*/
  138. @import "../../public/public_reset.css";
  139. .index_header {
  140. background-color: white;
  141. display: flex;
  142. flex-flow: column nowrap;
  143. padding: 30px 30px;
  144. }
  145. /* 全站首页logo\搜索框\快速定位按钮 */
  146. .index_header > .logo_search {
  147. display: flex;
  148. /* flex-flow: row nowrap; */
  149. align-items: center;
  150. }
  151. .index_header > .logo_search > div:nth-of-type(2) {
  152. /* 搜索框右对齐 */
  153. margin-left: auto;
  154. padding: 0px 30px;
  155. display: flex;
  156. /* flex-flow: row nowrap; */
  157. align-items: center;
  158. width: 300px;
  159. }
  160. /* 搜索框输入框 */
  161. .index_header > .logo_search input {
  162. width: 300px;
  163. align-self: end;
  164. height: 40px;
  165. border: 2px solid #ccc;
  166. border-radius: 10px;
  167. }
  168. /* 放大镜图标 */
  169. .index_header > .logo_search label {
  170. font-size: 2rem;
  171. }
  172. /* 字体图标 点赞 评论 下载 会员等 */
  173. .index_header > .logo_search span {
  174. font-size: 2rem;
  175. padding: 0px 5px;
  176. }
  177. .index_header > .logo_search span:hover {
  178. color: red;
  179. }
  180. /* 全站首页导航 */
  181. .index_header > .nav {
  182. margin: 20px 0px;
  183. /* 整体布局为弹性布局 */
  184. display: flex;
  185. /* flex-flow: row nowrap; */
  186. justify-content: space-between;
  187. align-items: center;
  188. }
  189. /* 首页导航中每一个小的导航块 */
  190. .index_header > .nav > .detail {
  191. width: 300px;
  192. height: 50px;
  193. display: flex;
  194. /* flex-flow: row nowrap; */
  195. justify-content: space-evenly;
  196. align-items: center;
  197. }
  198. /* 导航块前面的字体图标 */
  199. .index_header > .nav > .detail > div:first-of-type > span {
  200. font-size: 3rem;
  201. color: red;
  202. }
  203. /* 字体图标后的分类导航提示 */
  204. .index_header > .nav > .detail > div:nth-of-type(2) > p {
  205. color: #555;
  206. }
  207. /* 分类导航中的每一个小的导航链接 */
  208. .index_header > .nav > .detail > div:last-of-type {
  209. width: 170px;
  210. display: flex;
  211. border-left: 2px solid #ccc;
  212. /* 弹性布局主轴方向为横向换行,上面规定了宽度 */
  213. flex-flow: row wrap;
  214. justify-content: space-evenly;
  215. align-items: center;
  216. }
  217. .index_header > .nav > .detail > div:last-of-type > a {
  218. padding: 0px 5px;
  219. }
  220. /* 全站首页轮播图 */
  221. .index_header > .lunbo {
  222. margin-top: 10px;
  223. display: flex;
  224. /* flex-flow: row nowrap; */
  225. justify-content: space-evenly;
  226. align-items: center;
  227. }
  228. .index_header > .lunbo > div {
  229. height: 338px;
  230. }
  231. .index_header > .lunbo > div img {
  232. width: 100%;
  233. height: 100%;
  234. }
  235. /* 首页合作合作单位模块样式 indexLink.css*/
  236. @import "../../public/public_reset.css";
  237. /* 合作单位样式 */
  238. .work_link {
  239. /* 基本样式 */
  240. margin-top: 20px;
  241. background-color: white;
  242. max-height: 130px;
  243. padding: 15px 30px;
  244. /* 整体采用网格布局,单元格自动填充 */
  245. display: grid;
  246. grid-template-columns: repeat(auto-fill, 150px);
  247. grid-template-rows: repeat(auto-fill, 40px);
  248. justify-content: space-evenly;
  249. align-content: space-evenly;
  250. }
  251. /* 每个合作单位的链接被包在一个div中 */
  252. .work_link > div {
  253. font-size: 1.5rem;
  254. /* 设置为弹性布局,为了设置其中链接的对齐方式 */
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. }
  259. .work_link > div a {
  260. color: grey;
  261. }
  262. .work_link > div a:hover {
  263. color: red;
  264. }
  265. /* 首页大标题样式 indexTitle.css*/
  266. /* 首页大标题样式 */
  267. .indexTitle {
  268. width: 140px;
  269. height: 45px;
  270. /* 大标题下方有一条红色的下划线 */
  271. border-bottom: 4px solid red;
  272. margin-top: 20px;
  273. /* 居中显示 */
  274. margin-left: auto;
  275. margin-right: auto;
  276. }
  277. .indexTitle > h1 {
  278. font-size: xx-large;
  279. text-align: center;
  280. color: #555;
  281. letter-spacing: 3px;
  282. }
  283. /* 首页新闻资讯模块样式 index_article.css*/
  284. @import "../../static/css/reset.css";
  285. @import "../public/public_reset.css";
  286. .indexArticle {
  287. /* 基本样式 */
  288. margin: 20px auto;
  289. width: 1255px;
  290. height: 445px;
  291. background-color: white;
  292. border-radius: 10px;
  293. /* 新闻资讯中的内容按栅格化布局 */
  294. display: grid;
  295. /* 定义一个2行3列的表格 */
  296. grid-template-columns: 421px 350px 350px;
  297. grid-template-rows: 210px 210px;
  298. /* 栅格的填充方式为列优先填充 */
  299. grid-auto-flow: column;
  300. justify-content: space-evenly;
  301. align-content: center;
  302. }
  303. .indexArticle:hover {
  304. /* 给整个新闻资讯模块添加一个鼠标悬浮效果 */
  305. box-shadow: 0px 0px 10px #555;
  306. }
  307. .indexArticle a {
  308. font-size: 0.9rem;
  309. color: #555;
  310. }
  311. .indexArticle a:hover {
  312. color: red;
  313. }
  314. /* 新闻资讯中大图的对齐方式为居中对齐 */
  315. .indexArticle > div:first-of-type {
  316. /* justify-self: center;
  317. align-self: center; */
  318. /* 设置该项目在网格中为居中对齐 */
  319. place-self: center;
  320. }
  321. /* 新闻资讯中两个小图的布局 */
  322. .indexArticle > div:nth-of-type(2) {
  323. /* 两个小图布局为弹性布局 */
  324. display: flex;
  325. flex-flow: row nowrap;
  326. }
  327. .indexArticle > div:nth-of-type(2) > div {
  328. width: 200px;
  329. height: 135px;
  330. }
  331. /* 两个小图的大小充满整个div */
  332. .indexArticle > div:nth-of-type(2) > div img {
  333. width: 100%;
  334. height: 100%;
  335. }
  336. /* 新闻资讯中新闻和促销的链接样式 */
  337. .indexArticle > div:nth-last-of-type(-n + 4) {
  338. align-self: center;
  339. }
  340. .indexArticle > div:nth-last-of-type(-n + 4) div {
  341. padding: 5px 10px;
  342. }
  343. .indexArticle > div:nth-last-of-type(-n + 4) p {
  344. font-size: 1.5rem;
  345. color: red;
  346. }
  347. .indexArticle > div:nth-last-of-type(-n + 4) span {
  348. color: gray;
  349. }
  350. /* 首页图片专区模块样式 index_picture.css*/
  351. @import "../../static/css/reset.css";
  352. @import "../public/public_reset.css";
  353. /* 整个图片模块的样式 */
  354. .indexPicture {
  355. width: 1255px;
  356. margin: 20px auto;
  357. /* 整体设置为弹性布局,横向不换行 */
  358. display: flex;
  359. flex-flow: row nowrap;
  360. justify-content: space-evenly;
  361. }
  362. /* 图片模块中3个小模块的样式 */
  363. .indexPicture > .picture {
  364. /* 基本样式 */
  365. width: 410px;
  366. height: 495px;
  367. margin: 20px;
  368. background-color: white;
  369. border-radius: 10px;
  370. /* 每一个小模块中的布局方式为弹性布局,列为主轴 */
  371. display: flex;
  372. flex-flow: column nowrap;
  373. align-items: center;
  374. }
  375. /*3个图片小模块的鼠标悬浮样式 */
  376. .indexPicture > .picture:hover {
  377. box-shadow: 0px 0px 10px #555;
  378. }
  379. /* 每个图片小模块的头部标题样式 */
  380. .indexPicture > .picture > div:first-of-type {
  381. height: 70px;
  382. width: 380px;
  383. padding: 20px;
  384. border-bottom: 2px solid #ccc;
  385. }
  386. /* 图片模块头部大标题的样式 */
  387. .indexPicture > .picture > div:first-of-type > a {
  388. font-size: 1.7rem;
  389. color: #555;
  390. }
  391. .indexPicture > .picture > div:first-of-type > a:hover {
  392. color: red;
  393. }
  394. /* 图片模块头部大标题详情样式 */
  395. .indexPicture > .picture > div:first-of-type > span {
  396. padding-left: 30px;
  397. color: red;
  398. }
  399. /* 4个小图+链接的样式 */
  400. .indexPicture > .picture > div:last-of-type {
  401. margin-top: 20px;
  402. /* 设置为2行2列的网格布局 */
  403. display: grid;
  404. grid-template-rows: repeat(2, 185px);
  405. grid-template-columns: repeat(2, 195px);
  406. /* 填充方式为按行的方向填充 */
  407. grid-auto-flow: row;
  408. place-content: space-evenly;
  409. place-items: center;
  410. }
  411. .indexPicture > .picture > div:last-of-type > div {
  412. margin: 10px;
  413. }
  414. .indexPicture > .picture > div:last-of-type > div > a > img {
  415. /* 图片大小固定 */
  416. width: 100%;
  417. height: 100%;
  418. }
  419. /* 首页二手交易模块样式 index_shop.css*/
  420. @import "../public/public_reset.css";
  421. @import "../../static/css/reset.css";
  422. /* 设置所有的span标签为红色字体 */
  423. span {
  424. color: red;
  425. }
  426. /* 二手交易模块样式 */
  427. .indexShop {
  428. /* 基本样式 */
  429. width: 1255px;
  430. height: 595px;
  431. margin: 20px auto;
  432. padding: 10px;
  433. background-color: white;
  434. border-radius: 10px;
  435. /* 弹性布局,列为主轴 */
  436. display: flex;
  437. flex-flow: column nowrap;
  438. }
  439. /* 二手交易模块的鼠标悬浮效果 */
  440. .indexShop:hover {
  441. box-shadow: 0px 0px 10px #555;
  442. }
  443. .indexShop > div {
  444. margin: 10px 0px;
  445. }
  446. /* 二手交易模块内大标题样式 */
  447. .indexShop > div:first-of-type > a {
  448. font-size: 1.8rem;
  449. margin-right: 20px;
  450. }
  451. /* 二手交易分类导航样式 */
  452. .indexShop > div:nth-of-type(2) {
  453. border-top: 1px solid #ccc;
  454. }
  455. .indexShop > div:nth-of-type(2) > span {
  456. font-size: 1.6rem;
  457. }
  458. .indexShop > div:nth-of-type(2) > a {
  459. margin: 0px 10px;
  460. }
  461. /* 二手交易模块中物品列表和分类图片样式 */
  462. .indexShop > div:last-of-type {
  463. /* 弹性布局,行为主轴 */
  464. display: flex;
  465. flex-flow: row nowrap;
  466. height: 450px;
  467. }
  468. /* 二手交易物品列表样式 */
  469. .indexShop > div > .commList {
  470. width: 805px;
  471. /* 交易物品整体样式为弹性布局为弹布局,横向换行 */
  472. display: flex;
  473. flex-flow: row wrap;
  474. }
  475. /* 二手交易每个物品的样式 */
  476. .indexShop > div > .commList > div {
  477. /* 基本样式 */
  478. width: 186px;
  479. height: 200px;
  480. margin: 5px;
  481. /* 弹性布局,竖排不换行 */
  482. display: flex;
  483. flex-flow: column nowrap;
  484. justify-content: center;
  485. }
  486. /* 物品的图片和链接样式 */
  487. .indexShop > div > .commList > div > div:first-of-type {
  488. width: 186px;
  489. height: 130px;
  490. border: 1px solid #ccc;
  491. border-radius: 5px;
  492. }
  493. /* 物品的价格和分类样式 */
  494. .indexShop > div > .commList > div > div:last-of-type {
  495. display: flex;
  496. flex-flow: row nowrap;
  497. justify-content: space-between;
  498. }
  499. /* 物品的分类样式 */
  500. .indexShop > div > .commList > div > div:last-of-type > span:last-of-type {
  501. background-color: #55ce9f;
  502. padding: 2px 3px;
  503. border-radius: 3px;
  504. color: white;
  505. }
  506. /* 物品的图片大小固定 */
  507. .indexShop > div > .commList img {
  508. width: 100%;
  509. height: 100%;
  510. }
  511. /* 二手交易右边分类图片样式 */
  512. .indexShop > div > .commClass {
  513. width: 450px;
  514. margin: auto;
  515. display: flex;
  516. flex-flow: row wrap;
  517. }
  518. .indexShop > div > .commClass > a > img {
  519. margin: 5px;
  520. }

2.栅格布局12列

  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>栅格12列布局</title>
  7. <link rel="stylesheet" href="css/style.css" />
  8. </head>
  9. <body>
  10. <div class="container">
  11. <div class="row">
  12. <div class="header col-12">header</div>
  13. </div>
  14. <div class="row">
  15. <div class="aside-left col-2">aside-left</div>
  16. <div class="main col-8">main</div>
  17. <div class="aside-right col-2">aside-right</div>
  18. </div>
  19. <div class="row">
  20. <div class="footer col-12">footer</div>
  21. </div>
  22. </div>
  23. </body>
  24. </html>
  • css示例代码
  1. * {
  2. padding: 0px;
  3. margin: 0px;
  4. box-sizing: border-box;
  5. }
  6. body {
  7. display: flex;
  8. justify-content: center;
  9. align-items: center;
  10. max-width: 100vw;
  11. min-height: 100vh;
  12. }
  13. .container {
  14. min-width: 920px;
  15. display: grid;
  16. gap: 5px;
  17. }
  18. .container > .row {
  19. display: grid;
  20. grid-template-columns: repeat(12, 1fr);
  21. gap: 5px;
  22. }
  23. .container > .row > .aside-left {
  24. background-color: hotpink;
  25. }
  26. .container > .row > .aside-right {
  27. background-color: indigo;
  28. }
  29. .container > .row > .main {
  30. background-color: lawngreen;
  31. }
  32. .container > .row:first-of-type,
  33. .row:last-of-type {
  34. min-height: 53px;
  35. }
  36. .container > .row:nth-of-type(2) {
  37. min-height: 500px;
  38. }
  39. .container > .row > .header {
  40. background-color: blue;
  41. }
  42. .container > .row > .footer {
  43. background-color: green;
  44. }
  45. .col-1 {
  46. grid-column-end: span 1;
  47. }
  48. .col-2 {
  49. grid-column-end: span 2;
  50. }
  51. .col-3 {
  52. grid-column-end: span 3;
  53. }
  54. .col-4 {
  55. grid-column-end: span 4;
  56. }
  57. .col-5 {
  58. grid-column-end: span 5;
  59. }
  60. .col-6 {
  61. grid-column-end: span 6;
  62. }
  63. .col-7 {
  64. grid-column-end: span 7;
  65. }
  66. .col-8 {
  67. grid-column-end: span 8;
  68. }
  69. .col-9 {
  70. grid-column-end: span 9;
  71. }
  72. .col-10 {
  73. grid-column-end: span 10;
  74. }
  75. .col-11 {
  76. grid-column-end: span 11;
  77. }
  78. .col-12 {
  79. grid-column-end: span 12;
  80. }

3.电子相册

  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. <link rel="stylesheet" href="static/css/style.css" />
  7. <title>电子相册</title>
  8. </head>
  9. <body>
  10. <h1>我的明星相册</h1>
  11. <div class="container">
  12. <div class="item">
  13. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  14. <a href="">明星相册</a>
  15. </div>
  16. <div class="item">
  17. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  18. <a href="">明星相册</a>
  19. </div>
  20. <div class="item">
  21. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  22. <a href="">明星相册</a>
  23. </div>
  24. <div class="item">
  25. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  26. <a href="">明星相册</a>
  27. </div>
  28. <div class="item">
  29. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  30. <a href="">明星相册</a>
  31. </div>
  32. <div class="item">
  33. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  34. <a href="">明星相册</a>
  35. </div>
  36. <div class="item">
  37. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  38. <a href="">明星相册</a>
  39. </div>
  40. <div class="item">
  41. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  42. <a href="">明星相册</a>
  43. </div>
  44. <div class="item">
  45. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  46. <a href="">明星相册</a>
  47. </div>
  48. <div class="item">
  49. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  50. <a href="">明星相册</a>
  51. </div>
  52. <div class="item">
  53. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  54. <a href="">明星相册</a>
  55. </div>
  56. <div class="item">
  57. <a href=""><img src="static/images/photo.jpg" alt="" /></a>
  58. <a href="">明星相册</a>
  59. </div>
  60. </div>
  61. </body>
  62. </html>
  • css示例代码
  1. * {
  2. padding: 0px;
  3. margin: 0px;
  4. box-sizing: border-box;
  5. }
  6. a {
  7. text-decoration: none;
  8. color: white;
  9. }
  10. a:hover {
  11. color: coral;
  12. }
  13. h1 {
  14. color: white;
  15. text-align: center;
  16. letter-spacing: 5px;
  17. font-size: 2.5rem;
  18. font-weight: 400;
  19. text-shadow: 2px 2px 2px #555;
  20. margin-top: 20px;
  21. }
  22. body {
  23. display: flex;
  24. flex-flow: column nowrap;
  25. justify-content: center;
  26. align-items: center;
  27. background-color: lightseagreen;
  28. }
  29. .container {
  30. min-width: 100vw;
  31. min-height: 100vh;
  32. padding: 50px;
  33. display: grid;
  34. grid-template-columns: repeat(auto-fill, 250px);
  35. grid-template-rows: repeat(auto-fill, 280px);
  36. justify-content: space-evenly;
  37. align-content: space-evenly;
  38. gap: 10px;
  39. }
  40. .container img {
  41. width: 100%;
  42. }
  43. .container > .item {
  44. padding: 30px;
  45. background-color: lightskyblue;
  46. display: flex;
  47. flex-flow: column nowrap;
  48. justify-content: center;
  49. align-items: center;
  50. border-radius: 10px;
  51. }
  52. .container > .item > a:first-of-type:hover {
  53. box-shadow: 0 0 10px #555;
  54. width: calc(100% * 1.02);
  55. background-color: lightslategray;
  56. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议