基于浏览器viewport进行的自适应布局(vw和vh)
<!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">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 100vw;
height: 100vh;
background: white;
color: white;
}
.box .background {
display: flex;
align-items: center;
justify-content: center;
height: 51vh;
width: 100vw;
background: #008de1;
}
.box .background .content {
width: 61vw;
height: 51vh;
background: #008de1;
}
.box .background .content .nav {
display: flex;
margin-top: 2.5vh;
width: 61vw;
height: 4.5vh;
background: #008de1;
line-height: 4.5vh;
text-align: center;
font-size: 0.9vw;
}
.box .background .content .nav .img {
background: gray;
width: 20%;
}
.box .background .content .nav .login {
padding-right: 1vw;
box-sizing: border-box;
background: #008de1;
width: 80%;
text-align: right;
letter-spacing: 0.5vw;
}
.box .background .content .nav .login button {
border: none;
font-size: 0.6vw;
color: white;
background: #5db423;
}
.box .background .content .search {
padding-top: 2.5vh;
margin-top: 12vh;
box-sizing: border-box;
width: 61vw;
height: 19vh;
background: 008de1;
}
.box .background .content .search .logo {
margin: auto;
width: 14vw;
height: 5vh;
background: gray;
margin-bottom: 6vh;
}
.box .background .content .search .input {
display: flex;
justify-content: center;
align-items: center;
margin: auto;
width: 28vw;
height: 5vh;
}
.box .background .content .search .input .left {
width: 80%;
height: 100%;
margin-right: 1%;
background: white;
}
.box .background .content .search .input .right {
width: 19%;
height: 100%;
background: red;
}
</style>
<body>
<div class="box">
<div class="background">
<div class="content">
<div class="nav">
<div class="img"></div>
<div class="login">
<span>注册|登录</span>
<button>我要开店</button>
</div>
</div>
<div class="search">
<div class="logo"></div>
<div class="input">
<div class="left"></div>
<div class="right"></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>