1、百分比布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title> %和rem 布局</title>
<style>
html {
font-size: 30px;
}
.box2 {
width: 10rem;
height: 10rem;
background-color: plum;
}
.box {
width: 80%;
height: 200px;
background-color: aquamarine;
}
.part {
width: 80%;
height: 80%;
background-color: pink;
}
</style>
</head>
<body>
<div class="box">
<div class="part"></div>
</div>
<div class="box2"></div>
</body>
</html>
2、rem布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>rem布局</title>
<style>
html {
font-size: 20px;
}
.r1 {
width: 2rem;
height: 2rem;
background-color: plum;
}
.r2 {
width: 40px;
height: 40px;
background-color: aquamarine;
}
</style>
</head>
<body>
<div class="r1"></div>
<div class="r2"></div>
</body>
</html>
3 媒体查询 @media screen
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@media screen</title>
<style>
.box {
width: 10rem;
height: 10rem;
background-color: pink;
margin-left: 20rem;
}
@media screen and (min-width: 1200px) {
html {
font-size: 20px;
}
}
@media screen and (max-width: 1200px) {
html {
font-size: 10px;
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
4 flex布局
5、vw 和 vh
(1条消息) 前端响应式布局原理与方案(详细版)_weixin_34273479的博客-CSDN博客https://blog.csdn.net/weixin_34273479/article/details/91401352?spm=1001.2101.3001.6650.1&depth_1-utm_relevant_index=2