版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
目录
1.需求
2.代码(注释清晰)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>携程首页demo</title>
<style>
* {
padding: 0;
margin: 0;
}
header {
width: 100%;
display: flex;
}
header>a {
flex: 1;
}
header>a>img {
width: 100%;
height: 180px;
}
main {
width: 100%;
padding: 0px 10px;
/* 防止出现左右滑动 */
box-sizing: border-box;
}
main>.item {
width: 100%;
height: 100px;
background-color: #2b7c27;
border-radius: 10px;
margin-top: 10px;
display: flex;
}
/* 左右布局flex左占1/3,右占2/3 */
main>.item>.left {
flex: 1;
}
main>.item>.right {
flex: 2;
/* 让父元素换行显示 */
flex-wrap: wrap;
/* 让父元素变为伸缩盒子,这样子元素就能换行了 */
display: flex;
}
main>.item>.right>a {
/* 必须为子元素设置宽度,且要超过父元素的宽度,不然不会换行 */
width: 50%;
display: block;
text-align: center;
color: #fff;
text-decoration: none;
line-height: 50px;
/* 设置边框 左和下 */
border-left: 1px solid #fff;
border-bottom: 1px solid #fff;
/* 上面加了边框,所以设置盒模型,防止换行 */
box-sizing: border-box;
}
/* 把每个item里的最后两个a的底部边框去除 */
main>.item>.right>a:nth-last-of-type(-n+2) {
border-bottom: none;
}
/* 为每个item设置颜色 */
main>.item:nth-of-type(2) {
background-color: #a035b4;
}
main>.item:nth-of-type(3) {
background-color: #227e95;
}
main>.item:nth-of-type(4) {
background-color: #a93982;
}
/* 底部三幅图,各占extra的1/3 */
main>.extra {
width: 100%;
display: flex;
}
main>.extra>a {
flex: 1;
}
footer {
width: 100%;
}
footer>nav {
width: 100%;
display: flex;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
}
footer>nav>a {
flex: 1;
color: green;
line-height: 30px;
text-align: center;
text-decoration: none;
}
footer>p {
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<header>
<a href="http://baidu.com">
<img src="images/header.png">
</a>
</header>
<main>
<section class="item">
<div class="left"></div>
<div class="right">
<a href="">周末游玩</a>
<a href="">今日去哪</a>
<a href="">海外旅游</a>
<a href="">特价机票</a>
</div>
</section>
<section class="item">
<div class="left"></div>
<div class="right">
<a href="">周末游玩</a>
<a href="">今日去哪</a>
<a href="">海外旅游</a>
<a href="">特价机票</a>
</div>
</section>
<section class="item">
<div class="left"></div>
<div class="right">
<a href="">周末游玩</a>
<a href="">今日去哪</a>
<a href="">海外旅游</a>
<a href="">特价机票</a>
</div>
</section>
<section class="item">
<div class="left"></div>
<div class="right">
<a href="">周末游玩</a>
<a href="">今日去哪</a>
<a href="">海外旅游</a>
<a href="">特价机票</a>
</div>
</section>
<div class="extra">
<a href=""><img src="images/img1.png"></a>
<a href=""><img src="images/img2.png"></a>
<a href=""><img src="images/img3.png"></a>
</div>
</main>
<footer>
<nav>
<a href="">电话预定</a>
<a href="">特价酒店</a>
<a href="">特色美食</a>
</nav>
<p>©2019携程旅行</p>
</footer>
</div>
</body>
</html>