效果
代码
<!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>Document</title>
<style>
*{
margin: 0;
}
html,body{
height: 100%;
}
.layout{
width: 100%;
height: 100%;
}
.layout-left{
height: 100%;
width: 200px;
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
background-color: coral;
opacity: 0.5;
}
.layout-right{
background-color: green;
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 200px;
opacity: 0.5;
}
.layout-center{
box-sizing: border-box;
background-color: gray;
height: 100%;
margin-left: 200px;
margin-right: 200px;
}
</style>
</head>
<body>
<div class="layout">
<div class="layout-left"></div>
<div class="layout-center"></div>
<div class="layout-right"></div>
</div>
</body>
</html>
重点:html
继承视口高度
html{
height: 100%; // 视口有多高, 这个height就是多高
}
body{
height: 100%; // html有多高,这个height就是多高
}
————————————————
版权声明:本文为CSDN博主「罐装面包」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_39291919/article/details/107237141