html 模拟携程网首页

目录架构

在这里插入图片描述

css/index.css

@font-face {
    font-family: 'icomoon';
    src: url('../fonts/icomoon.eot?8ahhy7');
    src: url('../fonts/icomoon.eot?8ahhy7#iefix') format('embedded-opentype'),
    url('../fonts/icomoon.ttf?8ahhy7') format('truetype'),
    url('../fonts/icomoon.woff?8ahhy7') format('woff'),
    url('../fonts/icomoon.svg?8ahhy7#icomoon') format('svg');
    font-weight: normal;
    font-style: normal;
    font-display: block;
}

body {
    min-width: 320px;
    max-width: 540px;
    margin: 0 auto;
    color: #000000;
    background-color: #f2f2f2;
    -webkit-tap-highlight-color: transparent;
}

* {
    margin: 0;
    padding: 0;
}

a {
    text-decoration: none;
}

div {
    box-sizing: border-box;
}

ul li {
    list-style: none;
}

.search-index {
    display: flex;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 44px;
    min-width: 320px;
    max-width: 540px;
    background: -webkit-linear-gradient(rgb(114,136,153),rgb(196,216,229));
    opacity: 0.7;
    transition: all .5s;
}

.search-index .search {
    position: relative;
    flex: 1;
    height: 26px;
    margin: 6px 10px;
    font-size: 12px;
    line-height: 24px; /*因为采用的c3模型,要减去上下padding*/
    padding-left: 25px;
    color: #666666;
    border: 1px solid #cccccc;
    border-radius: 50px;
}

.search-index .search::before {
    content: ""; /*必须写, 不然不显示*/
    position: absolute;
    display: block;
    top: 5px;
    left: 5px;
    width: 19px;
    height: 19px;
    background: url("../images/pic.png") no-repeat 0 0px;
    background-size: 21px auto;
}

.search-index .user {
    width: 44px;
    height: 44px;
    text-align: center;
    /*background: url("../images/pic.png") no-repeat 0 -41px;*/
    /*background-size: 21px auto;*/
    font-size: 12px;
    color: white;
}

.search-index .user::before {
    content: ""; /*必须写, 不然不显示*/
    display: block;
    width: 22px;
    height: 22px;
    margin: 3px auto;
    background: url("../images/pic.png") no-repeat 0 -35px;
    background-size: 21px auto;
}

.focus img {
    width: 100%;
}

.local-nav {
    display: flex;
    height: 64px;
    background-color: white;
    border-radius: 8px;
    margin: 3px 4px;
}

.local-nav li {
    flex: 1;
}

.local-nav a {
    display: flex;
    flex-direction: column; /*主轴y轴*/
    align-items: center; /*侧轴居中*/
    color: #222222;
    font-size: 12px;
}

.local-nav li [class^='local-nav-icon'] { /*属性选择器,以local-nav-icon开头*/
    width: 40px;
    height: 40px;
    margin-top: 8px;
    background: url("../images/pic2.png") 0 0 no-repeat;
    background-size: 40px auto;
}

.local-nav li .local-nav-icon-icon2 {
    background-position: 0 -40px;
}

.local-nav li .local-nav-icon-icon3 {
    background-position: 0 -80px;
}

.local-nav li .local-nav-icon-icon4 {
    background-position: 0 -120px;
}

.local-nav li .local-nav-icon-icon5 {
    background-position: 0 -160px;
}

nav {
    overflow: hidden;
    border-radius: 8px;
    margin: 0 4px 3px;
}

.nav-common {
    display: flex;
    height: 88px;
    background-color: pink;
}

.nav-common:nth-child(1) {
    background: -webkit-linear-gradient(left, rgb(250, 90, 86), rgb(251, 131, 80));
}

.nav-common:nth-child(2) {
    margin: 3px 0;
    background: -webkit-linear-gradient(left, rgb(75, 144, 237), rgb(83, 187, 237));
}

.nav-common:nth-child(3) {
    background: -webkit-linear-gradient(left, rgb(53, 194, 169), rgb(107, 213, 88));
}

.nav-common .nav-items {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.nav-common .nav-items:nth-child(-n+2) {
    border-right: 1px solid #ffffff;
}

.nav-common .nav-items a {
    flex: 1;
    color: #ffffff;
    font-size: 14px;
    text-align: center;
    text-shadow: 1px 1px rgb(0, 0, .2);
    line-height: 44px;
}

.nav-common .nav-items:nth-child(1) a {
    background: url("../images/bg1.png") no-repeat bottom right;
    line-height: 80px;
    text-align: left;
    padding: 0 20px;
    background-size: 73px auto;
}

.nav-common:nth-child(2) .nav-items:nth-child(1) a {
    background: url("../images/bg2.png") no-repeat bottom right;
    background-size: 73px auto;
}

.nav-common:nth-child(3) .nav-items:nth-child(1) a {
    background: url("../images/bg3.png") no-repeat bottom right;
    background-size: 73px auto;
}

.nav-common .nav-items a:nth-child(1) {
    border-bottom: 1px solid #ffffff;
}

.nav-common .nav-items:nth-child(1) a {
    border-bottom: none;
}

.subnav-entry {
    display: flex;
    flex-wrap: wrap;
    border-radius: 8px;
    background-color: #fff;
    margin: 0 4px;
}

.subnav-entry li {
    /*flex支持百分比*/
    flex: 20%;
    margin-top: 5px;
}

.subnav-entry li a {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 12px;
}

[class^='subnav-entry-icon'] {
    width: 28px;
    height: 28px;
    /*margin-top: 4px;*/
    background: url("../images/un_ico_subnav2x@v7.152.png") 0 0 no-repeat;
    background-size: 28px auto;
}

.sales-box {
    border-top: 1px solid #bbb;
    background-color: #fff;
    margin: 10px 0;
}

.sales-hd {
    position: relative;
    height: 44px;
    border-bottom: 1px solid #ccc;
}

.sales-hd h2 {
    /*position: relative;*/
    text-indent: -999px;
    overflow: hidden;
}

.sales-hd h2::after {
    position: absolute;
    top: 14px;
    left: 8px;
    content: "";
    width: 79px;
    height: 15px;
    background: url(../upload/hot.png) no-repeat 0 -20px;
    background-size: 79px auto;
}

.more {
    position: absolute;
    right: 5px;
    top: 9px;
    background: -webkit-linear-gradient(left, #FF506C, #FF6BC6);
    border-radius: 15px;
    padding: 3px 20px 3px 10px;
    color: #fff;
}

.more::after {
    content: "";
    position: absolute;
    top: 9px;
    right: 9px;
    width: 7px;
    height: 7px;
    border-top: 2px solid #fff;
    border-right: 2px solid #fff;
    transform: rotate(45deg);
}

.row {
    display: flex;
}

.row a {
    flex: 1;
    border-bottom: 1px solid #eee;
}

.row a:nth-child(1) {
    border-right: 1px solid #eee;
}

.row a img {
    width: 100%;
}

.floor {
    display: flex;
}

.floor li {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 12px;
    line-height: 25px;
}
.floor li::before {
    font-size: 20px;
    color: skyblue;
}
.floor li:nth-child(1)::before{
    font-family: icomoon;
    content: '\e942';
}
.floor li:nth-child(2)::before{
    font-family: icomoon;
    content: '\e9c7';
}
.floor li:nth-child(3)::before{
    font-family: icomoon;
    content: '\e9fa';
}

/index.html

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link rel="stylesheet" href="css/normalize.css">
		<link rel="stylesheet" href="css/index.css">
		<script src="js/index.js"></script>
		<title>携程</title>
	</head>
	<body>
		<!--顶部搜索-->
		<div class="search-index">
			<div class="search">搜索:目的地/酒店/景点/航班号</div>
			<a href="" class="user">我 的</a>
		</div>
		<!--焦点图-->
		<div class="focus">
			<img src="upload/focus.jpg" alt="">
		</div>
		<!--导航栏-->
		<ul class="local-nav">
			<li>
				<a href="" title="攻略·景点">
					<span class="local-nav-icon-icon1"></span>
					<span>攻略·景点</span>
				</a>
			</li>
			<li>
				<a href="" title="攻略·景点">
					<span class="local-nav-icon-icon2"></span>
					<span>攻略·景点</span>
				</a>
			</li>
			<li>
				<a href="" title="攻略·景点">
					<span class="local-nav-icon-icon3"></span>
					<span>攻略·景点</span>
				</a>
			</li>
			<li>
				<a href="" title="攻略·景点">
					<span class="local-nav-icon-icon4"></span>
					<span>攻略·景点</span>
				</a>
			</li>
			<li>
				<a href="" title="攻略·景点">
					<span class="local-nav-icon-icon5"></span>
					<span>攻略·景点</span>
				</a>
			</li>

		</ul>
		<!--主导航栏-->
		<nav>
			<div class="nav-common">
				<div class="nav-items">
					<a href="">海外酒店</a>
				</div>
				<div class="nav-items">
					<a href="">海外酒店</a>
					<a href="">特价酒店</a>
				</div>
				<div class="nav-items">
					<a href="">海外酒店</a>
					<a href="">特价酒店</a>
				</div>
			</div>
			<div class="nav-common">
				<div class="nav-items">
					<a href="">海外酒店</a>
				</div>
				<div class="nav-items">
					<a href="">海外酒店</a>
					<a href="">特价酒店</a>
				</div>
				<div class="nav-items">
					<a href="">海外酒店</a>
					<a href="">特价酒店</a>
				</div>
			</div>
			<div class="nav-common">
				<div class="nav-items">
					<a href="">海外酒店</a>
				</div>
				<div class="nav-items">
					<a href="">海外酒店</a>
					<a href="">特价酒店</a>
				</div>
				<div class="nav-items">
					<a href="">海外酒店</a>
					<a href="">特价酒店</a>
				</div>
			</div>
		</nav>
		<!--侧导航栏-->
		<ul class="subnav-entry">
			<li>
				<a href="">
					<span class="subnav-entry-icon1"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon2"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon3"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon4"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon5"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon6"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon7"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon8"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon9"></span>
					<span>自由行</span>
				</a>
			</li>
			<li>
				<a href="">
					<span class="subnav-entry-icon10"></span>
					<span>自由行</span>
				</a>
			</li>
		</ul>
		<!-- 销售模块 -->
		<div class="sales-box">
			<div class="sales-hd">
				<h2>热门活动</h2>
				<a href="#" class="more">获取更多福利</a>
			</div>
			<div class="sales-bd">
				<div class="row">
					<a href="#">
						<img src="upload/p1.png" alt="">
					</a>
					<a href="#">
						<img src="upload/p2.jpg" alt="">
					</a>
				</div>
			</div>
		</div>
		<!--底部菜单-->
		<ul class="floor">
			<li>
				电话预定
			</li>
			<li>
				下载客户端
			</li>
			<li>
				我的
			</li>
		</ul>
	</body>
</html>

js/index.js

window.addEventListener('load', function () {
    var subnav_entry = document.querySelector('.subnav-entry');
    var li = subnav_entry.querySelectorAll('li');
    var y = 0;
    for (var i = 0; i < li.length; i++) {
        li[i].querySelector('span').style.backgroundPosition = '0 -' + y + 'px';
        y += 28;
    }
    var search_index = document.querySelector('.search-index');
    document.addEventListener('scroll', function () {
        if (window.pageYOffset > 100) {
            search_index.style.background = 'white';
            search_index.style.opacity = '1';
            console.log(search_index.style.backgroundColor)
        } else {
            search_index.style.background = '-webkit-linear-gradient(rgb(114,136,153),rgb(196,216,229))';
            search_index.style.opacity = '0.7';
            console.log(search_index.style.background)
        }
    })
})

css/normalize.css

/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */

/* Document
   ========================================================================== */

/**
 * 1. Correct the line height in all browsers.
 * 2. Prevent adjustments of font size after orientation changes in iOS.
 */

html {
    line-height: 1.15; /* 1 */
    -webkit-text-size-adjust: 100%; /* 2 */
}

/* Sections
   ========================================================================== */

/**
 * Remove the margin in all browsers.
 */

body {
    margin: 0;
}

/**
 * Render the `main` element consistently in IE.
 */

main {
    display: block;
}

/**
 * Correct the font size and margin on `h1` elements within `section` and
 * `article` contexts in Chrome, Firefox, and Safari.
 */

h1 {
    font-size: 2em;
    margin: 0.67em 0;
}

/* Grouping content
   ========================================================================== */

/**
 * 1. Add the correct box sizing in Firefox.
 * 2. Show the overflow in Edge and IE.
 */

hr {
    box-sizing: content-box; /* 1 */
    height: 0; /* 1 */
    overflow: visible; /* 2 */
}

/**
 * 1. Correct the inheritance and scaling of font size in all browsers.
 * 2. Correct the odd `em` font sizing in all browsers.
 */

pre {
    font-family: monospace, monospace; /* 1 */
    font-size: 1em; /* 2 */
}

/* Text-level semantics
   ========================================================================== */

/**
 * Remove the gray background on active links in IE 10.
 */

a {
    background-color: transparent;
}

/**
 * 1. Remove the bottom border in Chrome 57-
 * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
 */

abbr[title] {
    border-bottom: none; /* 1 */
    text-decoration: underline; /* 2 */
    text-decoration: underline dotted; /* 2 */
}

/**
 * Add the correct font weight in Chrome, Edge, and Safari.
 */

b,
strong {
    font-weight: bolder;
}

/**
 * 1. Correct the inheritance and scaling of font size in all browsers.
 * 2. Correct the odd `em` font sizing in all browsers.
 */

code,
kbd,
samp {
    font-family: monospace, monospace; /* 1 */
    font-size: 1em; /* 2 */
}

/**
 * Add the correct font size in all browsers.
 */

small {
    font-size: 80%;
}

/**
 * Prevent `sub` and `sup` elements from affecting the line height in
 * all browsers.
 */

sub,
sup {
    font-size: 75%;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
}

sub {
    bottom: -0.25em;
}

sup {
    top: -0.5em;
}

/* Embedded content
   ========================================================================== */

/**
 * Remove the border on images inside links in IE 10.
 */

img {
    border-style: none;
}

/* Forms
   ========================================================================== */

/**
 * 1. Change the font styles in all browsers.
 * 2. Remove the margin in Firefox and Safari.
 */

button,
input,
optgroup,
select,
textarea {
    font-family: inherit; /* 1 */
    font-size: 100%; /* 1 */
    line-height: 1.15; /* 1 */
    margin: 0; /* 2 */
}

/**
 * Show the overflow in IE.
 * 1. Show the overflow in Edge.
 */

button,
input { /* 1 */
    overflow: visible;
}

/**
 * Remove the inheritance of text transform in Edge, Firefox, and IE.
 * 1. Remove the inheritance of text transform in Firefox.
 */

button,
select { /* 1 */
    text-transform: none;
}

/**
 * Correct the inability to style clickable types in iOS and Safari.
 */

button,
[type="button"],
[type="reset"],
[type="submit"] {
    -webkit-appearance: button;
}

/**
 * Remove the inner border and padding in Firefox.
 */

button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
    border-style: none;
    padding: 0;
}

/**
 * Restore the focus styles unset by the previous rule.
 */

button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
    outline: 1px dotted ButtonText;
}

/**
 * Correct the padding in Firefox.
 */

fieldset {
    padding: 0.35em 0.75em 0.625em;
}

/**
 * 1. Correct the text wrapping in Edge and IE.
 * 2. Correct the color inheritance from `fieldset` elements in IE.
 * 3. Remove the padding so developers are not caught out when they zero out
 *    `fieldset` elements in all browsers.
 */

legend {
    box-sizing: border-box; /* 1 */
    color: inherit; /* 2 */
    display: table; /* 1 */
    max-width: 100%; /* 1 */
    padding: 0; /* 3 */
    white-space: normal; /* 1 */
}

/**
 * Add the correct vertical alignment in Chrome, Firefox, and Opera.
 */

progress {
    vertical-align: baseline;
}

/**
 * Remove the default vertical scrollbar in IE 10+.
 */

textarea {
    overflow: auto;
}

/**
 * 1. Add the correct box sizing in IE 10.
 * 2. Remove the padding in IE 10.
 */

[type="checkbox"],
[type="radio"] {
    box-sizing: border-box; /* 1 */
    padding: 0; /* 2 */
}

/**
 * Correct the cursor style of increment and decrement buttons in Chrome.
 */

[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
    height: auto;
}

/**
 * 1. Correct the odd appearance in Chrome and Safari.
 * 2. Correct the outline style in Safari.
 */

[type="search"] {
    -webkit-appearance: textfield; /* 1 */
    outline-offset: -2px; /* 2 */
}

/**
 * Remove the inner padding in Chrome and Safari on macOS.
 */

[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
}

/**
 * 1. Correct the inability to style clickable types in iOS and Safari.
 * 2. Change font properties to `inherit` in Safari.
 */

::-webkit-file-upload-button {
    -webkit-appearance: button; /* 1 */
    font: inherit; /* 2 */
}

/* Interactive
   ========================================================================== */

/*
 * Add the correct display in Edge, IE 10+, and Firefox.
 */

details {
    display: block;
}

/*
 * Add the correct display in all browsers.
 */

summary {
    display: list-item;
}

/* Misc
   ========================================================================== */

/**
 * Add the correct display in IE 10+.
 */

template {
    display: none;
}

/**
 * Add the correct display in IE 10.
 */

[hidden] {
    display: none;
}

  • 9
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值