HTML5使用伸缩布局实现网页的自适应

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>flex弹性布局</title>
<style>
*{
padding: 0;
margin: 0;
}
header{
width: 100%;
display: flex;
}
header > a{
flex: 1;
}
header > a >img{
width: 100%;
}

main{
width: 100%;
padding: 0 10px;
box-sizing: border-box;
}
main > .item{
width: 100%;
height: 100px;
background-color: #57c3ae;
border-radius: 10px;
margin-top: 10px;
display: flex;
}
main > .item:nth-last-of-type(2){
background-color: #3c7267;
}
main > .item:nth-last-of-type(3){
background-color: #332f38;
}
main > .item:nth-last-of-type(4){
background-color: #723c4c;
}
main > .item >.left{
flex: 1;
}
main > .item >.right{
flex: 2;
flex-wrap: wrap;
display: flex;
}
main > .item >.right >a{
display: block;
width: 50%;
border-left: 1px solid #fff;
border-bottom: 1px solid #fff;
box-sizing: border-box;
line-height: 50px;
color: #fff;
text-decoration: none;
text-align: center;
}
main > .item >.right >a :nth-last-of-type(-n+2){
border-bottom: none;
}

main >.extra{
width:100%;
display: flex;
}
main >.extra >a {
flex:1;
}
main >.extra >a >img {
width:100%;
}

footer{
width:100%;
font-size: 13px;
}
footer > nav{
width:100%;
display: flex;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
footer > nav > a{
flex: 1;
line-height: 30px;
text-align: center;
color: #888;
text-decoration: none;
}
footer > .link{
text-align: center;
line-height: 25px;
}
footer > .copyRight{
text-align: center;
}
</style>
</head>
<body>
<div class="contai">
<header>
<a href="">
<img src="./images/test1.jpg" alt="">
</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>
<section class="extra">
<a href="">
<img src="./images/she.jpg" alt="">
</a>
<a href="">
<img src="./images/telangpu.jpg" alt="">
</a>
</section>
</main>
<footer>
<nav>
<a href="">电话预定</a>
<a href="">下载客户端</a>
<a href="">我的</a>
</nav>
<p class="link">
<a href="">网站地图</a>
<a href="">ENGLISH</a>
<a href="">电话地址</a>
</p>
<p class="copyRight">&copy;2015 携程旅行</p>
</footer>
</div>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/liuhp/p/9704154.html