• 移动端携程网首页flex布局完整制做(详细代码版)含footer部分


    目录

     

    1、样式展示

     2、全部代码

    2.1、index.htnl文件

    2.2、index.css文件

    3、分布研究

    3.1 初始准备

    3.2在index.css文件中写body的样式,引入字体图标等基本设置

    3.3搜索模块的制作

    3.4、focus模块制作

    3.5、局部导航栏的制作

    3.6、nav部分

    3.7、sub-nav 部分

    3.8、剩余模块(sales模块、service模块、footer模块)


    文章有点长,可以点击目录查看相应内容

    1、样式展示

     2、全部代码

    2.1、index.htnl文件

    1. <!DOCTYPE html>
    2. <html lang="en">
    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. user-scalable=no,maximum-scale=1.0,minimum-scale=1.0">
    8. <title>携程在手,畅通无阻</title>
    9. <link rel="stylesheet" href="css/normalize.css">
    10. <link rel="stylesheet" href="css/index.css">
    11. </head>
    12. <body>
    13. <!-- 搜索模块 -->
    14. <div class="search-index">
    15. <div class="search">
    16. 搜索:目的地/酒店/景点/航班号
    17. </div>
    18. <a href="#" class="user">我 的</a>
    19. </div>
    20. <!-- focus模块 -->
    21. <div class="focus">
    22. <a href="#" title="高速享受慢生活">
    23. <img src="upload/focus.jpg" alt="">
    24. </a>
    25. </div>
    26. <!-- 局部导航栏模块 -->
    27. <ul class="local-nav">
    28. <li>
    29. <a href="#" title="景点·玩乐">
    30. <span class="local-nav-icon1"></span>
    31. <span>景点·玩乐</span>
    32. </a>
    33. </li>
    34. <li>
    35. <a href="#" title="周边游">
    36. <span class="local-nav-icon1"></span>
    37. <span>周边游</span>
    38. </a>
    39. </li>
    40. <li>
    41. <a href="#" title="美食林">
    42. <span class="local-nav-icon1"></span>
    43. <span>美食林</span>
    44. </a>
    45. </li>
    46. <li>
    47. <a href="#" title="一日游">
    48. <span class="local-nav-icon1"></span>
    49. <span>一日游</span>
    50. </a>
    51. </li>
    52. <li>
    53. <a href="#" title="当地攻略">
    54. <span class="local-nav-icon1"></span>
    55. <span>当地攻略</span>
    56. </a>
    57. </li>
    58. </ul>
    59. <!-- nav部分 -->
    60. <nav class="nav">
    61. <div class="nav-common">
    62. <div class="nav-items">
    63. <a href="#">酒店</a>
    64. </div>
    65. <div class="nav-items">
    66. <a href="#">海外酒店</a>
    67. <a href="#">特价酒店</a>
    68. </div>
    69. <div class="nav-items">
    70. <a href="#">团购</a>
    71. <a href="#">民宿·客栈</a>
    72. </div>
    73. </div>
    74. <div class="nav-common">
    75. <div class="nav-items">
    76. <a href="#">机票</a>
    77. </div>
    78. <div class="nav-items">
    79. <a href="#">火车票</a>
    80. <a href="#">特价机票</a>
    81. </div>
    82. <div class="nav-items">
    83. <a href="#">汽车票·船票</a>
    84. <a href="#">专车·租车</a>
    85. </div>
    86. </div>
    87. <div class="nav-common">
    88. <div class="nav-items">
    89. <a href="#">旅游</a>
    90. </div>
    91. <div class="nav-items">
    92. <a href="#">门票</a>
    93. <a href="#">目的地攻略</a>
    94. </div>
    95. <div class="nav-items">
    96. <a href="#">游轮旅行</a>
    97. <a href="#">定制旅行 </a>
    98. </div>
    99. </div>
    100. </nav>
    101. <!-- 侧导航栏 -->
    102. <ul class="subnav-entry">
    103. <li>
    104. <a href="#" title="电话费">
    105. <span></span>
    106. <span>电话费</span>
    107. </a>
    108. </li>
    109. <li>
    110. <a href="#" title="保险·签证">
    111. <span></span>
    112. <span>保险·签证</span>
    113. </a>
    114. </li>
    115. <li>
    116. <a href="#" title="外币兑换">
    117. <span></span>
    118. <span>外币兑换</span>
    119. </a>
    120. </li>
    121. <li>
    122. <a href="#" title="购物">
    123. <span></span>
    124. <span>购物</span>
    125. </a>
    126. </li>
    127. <li>
    128. <a href="#" title="当地向导">
    129. <span></span>
    130. <span>当地向导</span>
    131. </a>
    132. </li>
    133. <li>
    134. <a href="#" title="自由行">
    135. <span></span>
    136. <span>自由行</span>
    137. </a>
    138. </li>
    139. <li>
    140. <a href="#" title="境外玩乐">
    141. <span></span>
    142. <span>境外玩乐</span>
    143. </a>
    144. </li>
    145. <li>
    146. <a href="#" title="礼品卡">
    147. <span></span>
    148. <span>礼品卡</span>
    149. </a>
    150. </li>
    151. <li>
    152. <a href="#" title="信用卡">
    153. <span></span>
    154. <span>信用卡</span>
    155. </a>
    156. </li>
    157. <li>
    158. <a href="#" title="更多">
    159. <span></span>
    160. <span>更多</span>
    161. </a>
    162. </li>
    163. </ul>
    164. <!-- sales模块 -->
    165. <div class="sales">
    166. <div class="sales-hd">
    167. <!-- SEO优化 -->
    168. <h2>热门活动</h2>
    169. <a class="more">获取更多福利</a>
    170. </div>
    171. <div class="sales-bd">
    172. <div class="row">
    173. <a href="#">
    174. <img src="upload/pic1.jpg" alt="">
    175. </a>
    176. <a href="#">
    177. <img src="upload/pic2.jpg" alt="">
    178. </a>
    179. </div>
    180. <div class="row">
    181. <a href="#">
    182. <img src="upload/pic3.jpg" alt="">
    183. </a>
    184. <a href="#">
    185. <img src="upload/pic4.jpg" alt="">
    186. </a>
    187. </div>
    188. <div class="row">
    189. <a href="#">
    190. <img src="upload/pic5.jpg" alt="">
    191. </a>
    192. <a href="#">
    193. <img src="upload/pic6.jpg" alt="">
    194. </a>
    195. </div>
    196. </div>
    197. </div>
    198. <!-- service模块 -->
    199. <ul class="service">
    200. <li>
    201. <span></span>
    202. <span>电话预订</span>
    203. </li>
    204. <li>
    205. <span></span>
    206. <span>下载客户端</span>
    207. </li>
    208. <li>
    209. <span></span>
    210. <span>我的</span>
    211. </li>
    212. </ul>
    213. <!-- footer -->
    214. <footer>
    215. <h5>
    216. <a href="#">网站地图 </a>|
    217. <a href="#">language </a>|
    218. <a href="#">电脑版</a>
    219. </h5>
    220. <p>©2022携程旅行 | 沪ICP备08023580</p>
    221. </footer>
    222. </body>
    223. </html>

    2.2、index.css文件

    1. /* 字体图标 */
    2. @font-face {
    3. font-family: 'icomoon';
    4. src: url('../fonts/icomoon.eot?o1ezsk');
    5. src: url('../fonts/icomoon.eot?o1ezsk#iefix') format('embedded-opentype'), url('../fonts/icomoon.ttf?o1ezsk') format('truetype'), url('../fonts/icomoon.woff?o1ezsk') format('woff'), url('../fonts/icomoon.svg?o1ezsk#icomoon') format('svg');
    6. font-weight: normal;
    7. font-style: normal;
    8. font-display: block;
    9. }
    10. /* body常用初始化样式 */
    11. body {
    12. max-width: 540px;
    13. min-width: 320px;
    14. margin: 0 auto;
    15. font: normal 14px/1.5 "Microsoft Yahei";
    16. color: #000;
    17. background-color: #f2f2f2;
    18. /* 如果点击有高亮的设置透明 */
    19. -webkit-tap-highlight-color: transparent;
    20. /* 永远不会有横向导航条 */
    21. overflow-x: hidden;
    22. }
    23. div {
    24. box-sizing: border-box;
    25. }
    26. a {
    27. text-decoration: none;
    28. }
    29. h5 {
    30. padding: 0;
    31. margin: 0;
    32. }
    33. ul {
    34. margin: 0;
    35. padding: 0;
    36. list-style: none;
    37. }
    38. .search-index {
    39. display: flex;
    40. position: fixed;
    41. left: 50%;
    42. top: 0;
    43. transform: translateX(-50%);
    44. /* 兼容其他版本 */
    45. -webkit-transform: translateX(-50%);
    46. width: 100%;
    47. height: 44px;
    48. min-width: 320px;
    49. max-width: 540px;
    50. border-bottom: 1px solid #ccc;
    51. border-top: 1px solid #ccc;
    52. background-color: #f6f6f6;
    53. }
    54. .search-index .search {
    55. position: relative;
    56. flex: 1;
    57. height: 26px;
    58. border: 1px solid #ccc;
    59. margin: 7px 10px;
    60. padding-left: 25px;
    61. font-size: 12px;
    62. color: #666;
    63. line-height: 24px;
    64. box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
    65. border-radius: 5px;
    66. }
    67. .search-index .search::before {
    68. content: '';
    69. position: absolute;
    70. top: 5px;
    71. left: 5px;
    72. width: 15px;
    73. height: 15px;
    74. background: url(../images/sprite.png) -59px -279px no-repeat;
    75. background-size: 104px auto;
    76. }
    77. .search-index a {
    78. width: 44px;
    79. height: 44px;
    80. color: #2eaae0;
    81. font-size: 12px;
    82. text-align: center;
    83. }
    84. .search-index a::before {
    85. content: '';
    86. display: block;
    87. width: 23px;
    88. height: 23px;
    89. margin: 3px 0 0 11px;
    90. background: url(../images/sprite.png) -59px -193px no-repeat;
    91. background-size: 104px auto;
    92. }
    93. /* focus */
    94. .focus {
    95. margin-top: 44px;
    96. }
    97. .focus a img {
    98. width: 100%;
    99. }
    100. /* 局部导航栏 */
    101. .local-nav {
    102. overflow: hidden;
    103. display: flex;
    104. height: 64px;
    105. background-color: #fff;
    106. margin: 3px;
    107. border-radius: 8px;
    108. }
    109. .local-nav li {
    110. flex: 1;
    111. }
    112. .local-nav li a {
    113. display: flex;
    114. flex-direction: column;
    115. align-items: center;
    116. font-size: 12px;
    117. color: #222;
    118. }
    119. .local-nav li [class^='local-nav-icon'] {
    120. margin-top: 8px;
    121. margin-bottom: 2px;
    122. width: 32px;
    123. height: 32px;
    124. background: url(../images/localnav_bg.png) 0 0 no-repeat;
    125. background-size: 32px auto;
    126. }
    127. .local-nav li:nth-child(2) a span:nth-child(1) {
    128. background-position: 0 -32px;
    129. }
    130. .local-nav li:nth-child(3) a span:nth-child(1) {
    131. background-position: 0 -64px;
    132. }
    133. .local-nav li:nth-child(4) a span:nth-child(1) {
    134. background-position: 0 -96px;
    135. }
    136. .local-nav li:nth-child(5) a span:nth-child(1) {
    137. background-position: 0 -128px;
    138. }
    139. /* nav */
    140. .nav {
    141. margin-top: 5px;
    142. border-radius: 5px;
    143. overflow: hidden;
    144. }
    145. .nav-common {
    146. display: flex;
    147. height: 88px;
    148. margin-bottom: 3px;
    149. }
    150. .nav-common:nth-child(1) {
    151. background: -webkit-linear-gradient(left, #FA5B55, #FA984D);
    152. }
    153. .nav-common:nth-child(2) {
    154. background: -webkit-linear-gradient(left, #4B90ED, #53BBED);
    155. }
    156. .nav-common:nth-child(3) {
    157. background: -webkit-linear-gradient(left, #35c3a8, #6bd55b);
    158. }
    159. .nav-items {
    160. flex: 1;
    161. display: flex;
    162. flex-direction: column;
    163. align-items: center;
    164. }
    165. .nav-items:nth-child(-n+2) {
    166. border-right: 1px solid #fff;
    167. }
    168. .nav-items a {
    169. flex: 1;
    170. line-height: 44px;
    171. font-size: 14px;
    172. color: #fff;
    173. padding: 0 25px;
    174. text-shadow: 0 2px 2px rgba(0, 0, 0, .2);
    175. }
    176. .nav-items:nth-child(1) a {
    177. background: url(../images/hotel.png) bottom center no-repeat;
    178. background-size: 121px auto;
    179. }
    180. /* subnav-entry */
    181. .subnav-entry {
    182. overflow: hidden;
    183. padding-top: 5px;
    184. margin-top: 3px;
    185. display: flex;
    186. flex-wrap: wrap;
    187. background-color: #fff;
    188. border-radius: 5px;
    189. }
    190. .subnav-entry li {
    191. flex: 20%;
    192. }
    193. .subnav-entry li a {
    194. display: flex;
    195. padding-top: 7px;
    196. padding-bottom: 3px;
    197. flex-direction: column;
    198. align-items: center;
    199. }
    200. .subnav-entry li span:nth-child(1) {
    201. width: 28px;
    202. height: 28px;
    203. background: url(../images/subnav-bg.png) 0 0 no-repeat;
    204. background-size: 28px auto;
    205. }
    206. .subnav-entry li:nth-child(2) a span:nth-child(1) {
    207. background-position: 3px -28px;
    208. }
    209. .subnav-entry li:nth-child(3) a span:nth-child(1) {
    210. background-position: 3px -63px;
    211. }
    212. .subnav-entry li:nth-child(4) a span:nth-child(1) {
    213. background-position: 3px -100px;
    214. }
    215. .subnav-entry li:nth-child(5) a span:nth-child(1) {
    216. background-position: 3px -132px;
    217. }
    218. .subnav-entry li:nth-child(6) a span:nth-child(1) {
    219. background-position: 3px -164px;
    220. }
    221. .subnav-entry li:nth-child(7) a span:nth-child(1) {
    222. background-position: 3px -199px;
    223. }
    224. .subnav-entry li:nth-child(8) a span:nth-child(1) {
    225. background-position: 3px -232px;
    226. }
    227. .subnav-entry li:nth-child(9) a span:nth-child(1) {
    228. background-position: 3px -262px;
    229. }
    230. .subnav-entry li:nth-child(10) a span:nth-child(1) {
    231. background-position: 3px -291px;
    232. }
    233. /* sales */
    234. .sales {
    235. margin-top: 3px;
    236. }
    237. .sales-hd {
    238. position: relative;
    239. height: 44px;
    240. background-color: #fff;
    241. /* border-top: 1px solid #ccc; */
    242. border-bottom: 1px solid #ccc;
    243. }
    244. .sales-hd h2 {
    245. margin: 0;
    246. overflow: hidden;
    247. text-indent: -999px;
    248. }
    249. .sales-hd h2::after {
    250. content: '';
    251. position: absolute;
    252. left: 20px;
    253. top: 14px;
    254. width: 79px;
    255. height: 15px;
    256. background: url(../images/hot.png) 0px -20px no-repeat;
    257. background-size: 79px auto;
    258. }
    259. .sales-hd .more {
    260. position: absolute;
    261. right: 30px;
    262. top: 9px;
    263. font-size: 14px;
    264. padding: 2px 20px 2px 15px;
    265. border-radius: 15px;
    266. color: #fff;
    267. background: -webkit-linear-gradient(left, #ff5170, #ff6ac3);
    268. }
    269. .sales-hd .more::after {
    270. position: absolute;
    271. top: 8px;
    272. right: 11px;
    273. content: '';
    274. width: 8px;
    275. height: 8px;
    276. border-top: 1px solid #fff;
    277. border-right: 1px solid #fff;
    278. transform: rotate(45deg);
    279. }
    280. /* sales-bd */
    281. .sales-bd .row {
    282. display: flex;
    283. }
    284. .sales-bd .row:nth-child(-n+2) {
    285. border-bottom: 1px solid #ccc;
    286. }
    287. .sales-bd .row a {
    288. flex: 1;
    289. background-color: pink;
    290. height: 100%;
    291. }
    292. .sales-bd .row a:nth-child(1) {
    293. border-right: 1px solid #ccc;
    294. }
    295. .sales-bd .row a img {
    296. width: 100%;
    297. display: block;
    298. }
    299. /* service */
    300. .service {
    301. display: flex;
    302. height: 60px;
    303. border-bottom: 1px solid #ccc;
    304. border-top: 1px solid #ccc;
    305. margin-top: 5px;
    306. text-align: center;
    307. align-items: center;
    308. background-color: #fff;
    309. }
    310. .service li {
    311. flex: 1;
    312. display: flex;
    313. flex-direction: column;
    314. align-items: center;
    315. color: #333;
    316. }
    317. .service li span:nth-child(1) {
    318. position: relative;
    319. width: 30px;
    320. height: 30px;
    321. }
    322. .service li span:nth-child(1)::before {
    323. position: absolute;
    324. content: '\e964';
    325. left: 7px;
    326. top: 2px;
    327. font-family: 'icomoon';
    328. font-size: 18px;
    329. color: #ccc;
    330. }
    331. .service li:nth-child(2) span:nth-child(1)::before {
    332. position: absolute;
    333. content: '\ea3e';
    334. left: 4px;
    335. top: 2px;
    336. font-family: 'icomoon';
    337. font-size: 22px;
    338. color: #ccc;
    339. }
    340. .service li:nth-child(3) span:nth-child(1)::before {
    341. position: absolute;
    342. content: '\e902';
    343. left: 3px;
    344. top: 0px;
    345. font-family: 'icomoon';
    346. font-size: 22px;
    347. color: #ccc;
    348. }
    349. /* footer */
    350. footer {
    351. margin-top: 10px;
    352. text-align: center;
    353. color: #ccc;
    354. font-size: 12px;
    355. }
    356. footer h5 a {
    357. font-size: 12px;
    358. color: #999;
    359. font-weight: 400;
    360. }
    361. footer h5 a:nth-child(2) {
    362. position: relative;
    363. padding: 0 15px;
    364. }
    365. footer h5 a:nth-child(2)::before {
    366. content: '\e910';
    367. font-family: 'icomoon';
    368. position: absolute;
    369. top: 0;
    370. left: 0;
    371. width: 10px;
    372. height: 10px;
    373. }
    374. footer h5 a:nth-child(2)::after {
    375. content: '\e959';
    376. font-family: 'icomoon';
    377. position: absolute;
    378. top: 2px;
    379. right: 6px;
    380. width: 10px;
    381. height: 10px;
    382. }

    3、分布研究

    3.1 初始准备

    文件夹的创建

    视口标签,title,链接css文件没问题吧!

    1. <meta name="viewport" content="width=device-width,initial-scale=1.0,
    2. user-scalable=no,maximum-scale=1.0,minimum-scale=1.0">
    3. <title>携程在手,畅通无阻</title>
    4. <link rel="stylesheet" href="css/normalize.css">
    5. <link rel="stylesheet" href="css/index.css">

    3.2在index.css文件中写body的样式,引入字体图标等基本设置

    注意:在index.css文件中

    1. /* 字体图标 */
    2. @font-face {
    3. font-family: 'icomoon';
    4. src: url('../fonts/icomoon.eot?o1ezsk');
    5. src: url('../fonts/icomoon.eot?o1ezsk#iefix') format('embedded-opentype'), url('../fonts/icomoon.ttf?o1ezsk') format('truetype'), url('../fonts/icomoon.woff?o1ezsk') format('woff'), url('../fonts/icomoon.svg?o1ezsk#icomoon') format('svg');
    6. font-weight: normal;
    7. font-style: normal;
    8. font-display: block;
    9. }
    10. /* body常用初始化样式 */
    11. body {
    12. max-width: 540px;
    13. min-width: 320px;
    14. margin: 0 auto;
    15. font: normal 14px/1.5 "Microsoft Yahei";
    16. color: #000;
    17. background-color: #f2f2f2;
    18. /* 如果点击有高亮的设置透明 */
    19. -webkit-tap-highlight-color: transparent;
    20. /* 永远不会有横向导航条 */
    21. overflow-x: hidden;
    22. }
    23. div {
    24. box-sizing: border-box;
    25. }
    26. a {
    27. text-decoration: none;
    28. }
    29. h5 {
    30. padding: 0;
    31. margin: 0;
    32. }
    33. ul {
    34. margin: 0;
    35. padding: 0;
    36. list-style: none;
    37. }

    3.3搜索模块的制作

     主要思路:

    1、让盒子的高度固定,只让他们的宽度随着屏幕的大小而变化!

    2、search-index 父盒子固定定位,固定定位的盒子必须有宽度,所以让他的宽度为100%

    3、固定定位的盒子,是以屏幕为准的,所以body中的margin:0 auto;对他不管用

    4、因此他使用left:50%;(让他的最左边移动到屏幕的一半位置),再使用transform:translateX(-50%) (这里的50%是以当前移动的盒子为准的),就是让这个盒子再往左移动盒子本身一半的长度

    5、flex布局可以无限加,他爹有display:flex,它还可以加

    6、flex布局中的flex属性,只能是他的亲爹有display:flex;才能正常平均分配。

    如果他爷爷有display:flex,他爹没有display:flex,那么他不能平均分配他爹的长度!

    5、右边小盒子固定大小,左边小盒子flex:1,平分剩余部分,从而使左边的盒子能根据屏幕的大小放大和缩小。

    index.html中

    1. <!-- 搜索模块 -->
    2. <div class="search-index">
    3. <div class="search">
    4. 搜索:目的地/酒店/景点/航班号
    5. </div>
    6. <a href="#" class="user">我 的</a>
    7. </div>

    index.css文件中

    1. /* 搜索模块 */
    2. .search-index {
    3. display: flex;
    4. position: fixed;
    5. left: 50%;
    6. top: 0;
    7. transform: translateX(-50%);
    8. /* 兼容其他版本 */
    9. -webkit-transform: translateX(-50%);
    10. width: 100%;
    11. height: 44px;
    12. min-width: 320px;
    13. max-width: 540px;
    14. border-bottom: 1px solid #ccc;
    15. border-top: 1px solid #ccc;
    16. background-color: #f6f6f6;
    17. }
    18. .search-index .search {
    19. position: relative;
    20. flex: 1;
    21. height: 26px;
    22. border: 1px solid #ccc;
    23. margin: 7px 10px;
    24. padding-left: 25px;
    25. font-size: 12px;
    26. color: #666;
    27. line-height: 24px;
    28. box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
    29. border-radius: 5px;
    30. }
    31. .search-index .search::before {
    32. content: '';
    33. position: absolute;
    34. top: 5px;
    35. left: 5px;
    36. width: 15px;
    37. height: 15px;
    38. background: url(../images/sprite.png) -59px -279px no-repeat;
    39. background-size: 104px auto;
    40. }
    41. .search-index a {
    42. width: 44px;
    43. height: 44px;
    44. color: #2eaae0;
    45. font-size: 12px;
    46. text-align: center;
    47. }
    48. .search-index a::before {
    49. content: '';
    50. display: block;
    51. width: 23px;
    52. height: 23px;
    53. margin: 3px 0 0 11px;
    54. background: url(../images/sprite.png) -59px -193px no-repeat;
    55. background-size: 104px auto;
    56. }

    3.4、focus模块制作

    index.html文件

    1. <!-- focus模块 -->
    2. <div class="focus">
    3. <a href="#" title="高速享受慢生活">
    4. <img src="upload/focus.jpg" alt="">
    5. </a>
    6. </div>

    index.css文件

    高度固定,往里面放图片,让他的长度跟随a的长度即可

    1. /* focus */
    2. .focus {
    3. margin-top: 44px;
    4. }
    5. .focus a img {
    6. width: 100%;
    7. }

    3.5、局部导航栏的制作

     主要思路:

    1、大盒子里面包含五个小盒子     ul>li*5   

    2、大盒子display:flex;  主轴方向为横向(row)五个小盒子flex:1;  平分大盒子的长度,高度用里面的撑开即可。

    3、li 盒子中又分上下两个模块,上边图像,下边文字;又可以使用flex布局,主轴方向为纵向(column)。

    4、给图像定长和定宽,再往里面添加背景图片即可(里面用到精灵图技术),千万不要忘记缩放相应的倍数。

    index.html文件

    1. <!-- 局部导航栏模块 -->
    2. <ul class="local-nav">
    3. <li>
    4. <a href="#" title="景点·玩乐">
    5. <span class="local-nav-icon1"></span>
    6. <span>景点·玩乐</span>
    7. </a>
    8. </li>
    9. <li>
    10. <a href="#" title="周边游">
    11. <span class="local-nav-icon1"></span>
    12. <span>周边游</span>
    13. </a>
    14. </li>
    15. <li>
    16. <a href="#" title="美食林">
    17. <span class="local-nav-icon1"></span>
    18. <span>美食林</span>
    19. </a>
    20. </li>
    21. <li>
    22. <a href="#" title="一日游">
    23. <span class="local-nav-icon1"></span>
    24. <span>一日游</span>
    25. </a>
    26. </li>
    27. <li>
    28. <a href="#" title="当地攻略">
    29. <span class="local-nav-icon1"></span>
    30. <span>当地攻略</span>
    31. </a>
    32. </li>
    33. </ul>

    index.css文件

    1. /* 局部导航栏 */
    2. .local-nav {
    3. overflow: hidden;
    4. display: flex;
    5. height: 64px;
    6. background-color: #fff;
    7. margin: 3px;
    8. border-radius: 8px;
    9. }
    10. .local-nav li {
    11. flex: 1;
    12. }
    13. .local-nav li a {
    14. display: flex;
    15. flex-direction: column;
    16. align-items: center;
    17. font-size: 12px;
    18. color: #222;
    19. }
    20. .local-nav li [class^='local-nav-icon'] {
    21. margin-top: 8px;
    22. margin-bottom: 2px;
    23. width: 32px;
    24. height: 32px;
    25. background: url(../images/localnav_bg.png) 0 0 no-repeat;
    26. /* 千万别忘记缩放相应的比例 *
    27. background-size: 32px auto;
    28. }
    29. .local-nav li:nth-child(2) a span:nth-child(1) {
    30. background-position: 0 -32px;
    31. }
    32. .local-nav li:nth-child(3) a span:nth-child(1) {
    33. background-position: 0 -64px;
    34. }
    35. .local-nav li:nth-child(4) a span:nth-child(1) {
    36. background-position: 0 -96px;
    37. }
    38. .local-nav li:nth-child(5) a span:nth-child(1) {
    39. background-position: 0 -128px;
    40. }

    3.6、nav部分

     主要思路:

    1、写出一行来其他两行复制即可

    2、每一行中有三个模块使用flex布局,横向平均分配

    3、三个小模块中又采用上下的flex布局分配

    4、每一行中有线性渐变背景颜色

    5、每一行中的第一个给他添加背景图片

    index.html文件

    1. <!-- nav部分 -->
    2. <nav class="nav">
    3. <div class="nav-common">
    4. <div class="nav-items">
    5. <a href="#">酒店</a>
    6. </div>
    7. <div class="nav-items">
    8. <a href="#">海外酒店</a>
    9. <a href="#">特价酒店</a>
    10. </div>
    11. <div class="nav-items">
    12. <a href="#">团购</a>
    13. <a href="#">民宿·客栈</a>
    14. </div>
    15. </div>
    16. <div class="nav-common">
    17. <div class="nav-items">
    18. <a href="#">机票</a>
    19. </div>
    20. <div class="nav-items">
    21. <a href="#">火车票</a>
    22. <a href="#">特价机票</a>
    23. </div>
    24. <div class="nav-items">
    25. <a href="#">汽车票·船票</a>
    26. <a href="#">专车·租车</a>
    27. </div>
    28. </div>
    29. <div class="nav-common">
    30. <div class="nav-items">
    31. <a href="#">旅游</a>
    32. </div>
    33. <div class="nav-items">
    34. <a href="#">门票</a>
    35. <a href="#">目的地攻略</a>
    36. </div>
    37. <div class="nav-items">
    38. <a href="#">游轮旅行</a>
    39. <a href="#">定制旅行 </a>
    40. </div>
    41. </div>
    42. </nav>

    index.css文件

    1. /* nav */
    2. .nav {
    3. margin-top: 5px;
    4. border-radius: 5px;
    5. overflow: hidden;
    6. }
    7. .nav-common {
    8. display: flex;
    9. height: 88px;
    10. margin-bottom: 3px;
    11. }
    12. .nav-common:nth-child(1) {
    13. background: -webkit-linear-gradient(left, #FA5B55, #FA984D);
    14. }
    15. .nav-common:nth-child(2) {
    16. background: -webkit-linear-gradient(left, #4B90ED, #53BBED);
    17. }
    18. .nav-common:nth-child(3) {
    19. background: -webkit-linear-gradient(left, #35c3a8, #6bd55b);
    20. }
    21. .nav-items {
    22. flex: 1;
    23. display: flex;
    24. flex-direction: column;
    25. align-items: center;
    26. }
    27. .nav-items:nth-child(-n+2) {
    28. border-right: 1px solid #fff;
    29. }
    30. .nav-items a {
    31. flex: 1;
    32. line-height: 44px;
    33. font-size: 14px;
    34. color: #fff;
    35. padding: 0 25px;
    36. text-shadow: 0 2px 2px rgba(0, 0, 0, .2);
    37. }
    38. .nav-items:nth-child(1) a {
    39. background: url(../images/hotel.png) bottom center no-repeat;
    40. background-size: 121px auto;
    41. }

    3.7、sub-nav 部分

    主要思路 :

    1、还是使用flex布局,只是里面每个小盒子不给宽度的情况下是不能换行的,使用flex-wrap也不行.

    2、此时设置 flex:20%; 让每个小盒子占大盒子宽度的20%,那么五个盒子就能占满一行,在设置换行,就能五个一行平均分配空间了。

    3、小盒子里面还是使用flex布局,主轴为column

    index.html文件

    1. <!-- 侧导航栏 -->
    2. <ul class="subnav-entry">
    3. <li>
    4. <a href="#" title="电话费">
    5. <span></span>
    6. <span>电话费</span>
    7. </a>
    8. </li>
    9. <li>
    10. <a href="#" title="保险·签证">
    11. <span></span>
    12. <span>保险·签证</span>
    13. </a>
    14. </li>
    15. <li>
    16. <a href="#" title="外币兑换">
    17. <span></span>
    18. <span>外币兑换</span>
    19. </a>
    20. </li>
    21. <li>
    22. <a href="#" title="购物">
    23. <span></span>
    24. <span>购物</span>
    25. </a>
    26. </li>
    27. <li>
    28. <a href="#" title="当地向导">
    29. <span></span>
    30. <span>当地向导</span>
    31. </a>
    32. </li>
    33. <li>
    34. <a href="#" title="自由行">
    35. <span></span>
    36. <span>自由行</span>
    37. </a>
    38. </li>
    39. <li>
    40. <a href="#" title="境外玩乐">
    41. <span></span>
    42. <span>境外玩乐</span>
    43. </a>
    44. </li>
    45. <li>
    46. <a href="#" title="礼品卡">
    47. <span></span>
    48. <span>礼品卡</span>
    49. </a>
    50. </li>
    51. <li>
    52. <a href="#" title="信用卡">
    53. <span></span>
    54. <span>信用卡</span>
    55. </a>
    56. </li>
    57. <li>
    58. <a href="#" title="更多">
    59. <span></span>
    60. <span>更多</span>
    61. </a>
    62. </li>
    63. </ul>

    index.css文件

    1. /* subnav-entry */
    2. .subnav-entry {
    3. overflow: hidden;
    4. padding-top: 5px;
    5. margin-top: 3px;
    6. display: flex;
    7. flex-wrap: wrap;
    8. background-color: #fff;
    9. border-radius: 5px;
    10. }
    11. .subnav-entry li {
    12. flex: 20%;
    13. }
    14. .subnav-entry li a {
    15. display: flex;
    16. padding-top: 7px;
    17. padding-bottom: 3px;
    18. flex-direction: column;
    19. align-items: center;
    20. }
    21. .subnav-entry li span:nth-child(1) {
    22. width: 28px;
    23. height: 28px;
    24. background: url(../images/subnav-bg.png) 0 0 no-repeat;
    25. background-size: 28px auto;
    26. }
    27. .subnav-entry li:nth-child(2) a span:nth-child(1) {
    28. background-position: 3px -28px;
    29. }
    30. .subnav-entry li:nth-child(3) a span:nth-child(1) {
    31. background-position: 3px -63px;
    32. }
    33. .subnav-entry li:nth-child(4) a span:nth-child(1) {
    34. background-position: 3px -100px;
    35. }
    36. .subnav-entry li:nth-child(5) a span:nth-child(1) {
    37. background-position: 3px -132px;
    38. }
    39. .subnav-entry li:nth-child(6) a span:nth-child(1) {
    40. background-position: 3px -164px;
    41. }
    42. .subnav-entry li:nth-child(7) a span:nth-child(1) {
    43. background-position: 3px -199px;
    44. }
    45. .subnav-entry li:nth-child(8) a span:nth-child(1) {
    46. background-position: 3px -232px;
    47. }
    48. .subnav-entry li:nth-child(9) a span:nth-child(1) {
    49. background-position: 3px -262px;
    50. }
    51. .subnav-entry li:nth-child(10) a span:nth-child(1) {
    52. background-position: 3px -291px;
    53. }

    3.8、剩余模块(sales模块、service模块、footer模块)

    剩余部分和前面都差不多,就不再赘述。

    index.html文件

    1. <!-- sales模块 -->
    2. <div class="sales">
    3. <div class="sales-hd">
    4. <!-- SEO优化 -->
    5. <h2>热门活动</h2>
    6. <a class="more">获取更多福利</a>
    7. </div>
    8. <div class="sales-bd">
    9. <div class="row">
    10. <a href="#">
    11. <img src="upload/pic1.jpg" alt="">
    12. </a>
    13. <a href="#">
    14. <img src="upload/pic2.jpg" alt="">
    15. </a>
    16. </div>
    17. <div class="row">
    18. <a href="#">
    19. <img src="upload/pic3.jpg" alt="">
    20. </a>
    21. <a href="#">
    22. <img src="upload/pic4.jpg" alt="">
    23. </a>
    24. </div>
    25. <div class="row">
    26. <a href="#">
    27. <img src="upload/pic5.jpg" alt="">
    28. </a>
    29. <a href="#">
    30. <img src="upload/pic6.jpg" alt="">
    31. </a>
    32. </div>
    33. </div>
    34. </div>
    35. <!-- service模块 -->
    36. <ul class="service">
    37. <li>
    38. <span></span>
    39. <span>电话预订</span>
    40. </li>
    41. <li>
    42. <span></span>
    43. <span>下载客户端</span>
    44. </li>
    45. <li>
    46. <span></span>
    47. <span>我的</span>
    48. </li>
    49. </ul>
    50. <!-- footer -->
    51. <footer>
    52. <h5>
    53. <a href="#">网站地图 </a>|
    54. <a href="#">language </a>|
    55. <a href="#">电脑版</a>
    56. </h5>
    57. <p>©2022携程旅行 | 沪ICP备08023580</p>
    58. </footer>

    index.css文件

    1. /* sales */
    2. .sales {
    3. margin-top: 3px;
    4. }
    5. .sales-hd {
    6. position: relative;
    7. height: 44px;
    8. background-color: #fff;
    9. /* border-top: 1px solid #ccc; */
    10. border-bottom: 1px solid #ccc;
    11. }
    12. .sales-hd h2 {
    13. margin: 0;
    14. overflow: hidden;
    15. text-indent: -999px;
    16. }
    17. .sales-hd h2::after {
    18. content: '';
    19. position: absolute;
    20. left: 20px;
    21. top: 14px;
    22. width: 79px;
    23. height: 15px;
    24. background: url(../images/hot.png) 0px -20px no-repeat;
    25. background-size: 79px auto;
    26. }
    27. .sales-hd .more {
    28. position: absolute;
    29. right: 30px;
    30. top: 9px;
    31. font-size: 14px;
    32. padding: 2px 20px 2px 15px;
    33. border-radius: 15px;
    34. color: #fff;
    35. background: -webkit-linear-gradient(left, #ff5170, #ff6ac3);
    36. }
    37. .sales-hd .more::after {
    38. position: absolute;
    39. top: 8px;
    40. right: 11px;
    41. content: '';
    42. width: 8px;
    43. height: 8px;
    44. border-top: 1px solid #fff;
    45. border-right: 1px solid #fff;
    46. transform: rotate(45deg);
    47. }
    48. /* sales-bd */
    49. .sales-bd .row {
    50. display: flex;
    51. }
    52. .sales-bd .row:nth-child(-n+2) {
    53. border-bottom: 1px solid #ccc;
    54. }
    55. .sales-bd .row a {
    56. flex: 1;
    57. background-color: pink;
    58. height: 100%;
    59. }
    60. .sales-bd .row a:nth-child(1) {
    61. border-right: 1px solid #ccc;
    62. }
    63. .sales-bd .row a img {
    64. width: 100%;
    65. display: block;
    66. }
    67. /* service */
    68. .service {
    69. display: flex;
    70. height: 60px;
    71. border-bottom: 1px solid #ccc;
    72. border-top: 1px solid #ccc;
    73. margin-top: 5px;
    74. text-align: center;
    75. align-items: center;
    76. background-color: #fff;
    77. }
    78. .service li {
    79. flex: 1;
    80. display: flex;
    81. flex-direction: column;
    82. align-items: center;
    83. color: #333;
    84. }
    85. .service li span:nth-child(1) {
    86. position: relative;
    87. width: 30px;
    88. height: 30px;
    89. }
    90. .service li span:nth-child(1)::before {
    91. position: absolute;
    92. content: '\e964';
    93. left: 7px;
    94. top: 2px;
    95. font-family: 'icomoon';
    96. font-size: 18px;
    97. color: #ccc;
    98. }
    99. .service li:nth-child(2) span:nth-child(1)::before {
    100. position: absolute;
    101. content: '\ea3e';
    102. left: 4px;
    103. top: 2px;
    104. font-family: 'icomoon';
    105. font-size: 22px;
    106. color: #ccc;
    107. }
    108. .service li:nth-child(3) span:nth-child(1)::before {
    109. position: absolute;
    110. content: '\e902';
    111. left: 3px;
    112. top: 0px;
    113. font-family: 'icomoon';
    114. font-size: 22px;
    115. color: #ccc;
    116. }
    117. /* footer */
    118. footer {
    119. margin-top: 10px;
    120. text-align: center;
    121. color: #ccc;
    122. font-size: 12px;
    123. }
    124. footer h5 a {
    125. font-size: 12px;
    126. color: #999;
    127. font-weight: 400;
    128. }
    129. footer h5 a:nth-child(2) {
    130. position: relative;
    131. padding: 0 15px;
    132. }
    133. footer h5 a:nth-child(2)::before {
    134. content: '\e910';
    135. font-family: 'icomoon';
    136. position: absolute;
    137. top: 0;
    138. left: 0;
    139. width: 10px;
    140. height: 10px;
    141. }
    142. footer h5 a:nth-child(2)::after {
    143. content: '\e959';
    144. font-family: 'icomoon';
    145. position: absolute;
    146. top: 2px;
    147. right: 6px;
    148. width: 10px;
    149. height: 10px;
    150. }

  • 相关阅读:
    PyTorch笔记 - Convolution卷积运算的原理 (3)
    idea项目中java类名出现带 j 小红点,如何解决?
    远距离双目视觉测量系统纵深方向测量精度较低原因分析
    3D目标检测实战 | 详解2D/3D检测框交并比IoU计算(附Python实现)
    IE退役倒计时, Edge接棒
    Python爬虫-爬取全国各地市的邮编链接
    linux 批量关闭运行中的rsync进程
    简述事务隔离级别
    模拟滴答声
    机器学习(十九):梯度提升回归(GBR)
  • 原文地址:https://blog.csdn.net/m0_45142186/article/details/126732701