<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Height Demo</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
}
.container {
height: 100vh;
display: flex;
flex-direction: column;
}
.top {
height: 100px;
background-color: lightblue;
}
.bottom {
flex-grow: 1; /* 让下半部分的 div 沾满剩余高度 */
background-color: lightcoral;
}
</style>
</head>
<body>
<div class="container">
<div class="top">
<p>This is the top div</p>
</div>
<div class="bottom">
<p>This is the bottom div</p>
</div>
</div>
</body>
</html>
当你出现以上需求:上半部分高度固定,下半部分要求占满剩余部分,可以使用以上demo。
下半部分需要嵌入腾讯地图,当你把地图高度设置100%时,地图就会自动向上滚动,实际上canvas的高度在不停的增加,具体原因目前还不清楚。
解决方案:地图高度设置为99%。就会停止滚动,把多余的1%显示到地图上方。问题得到解决、但不是最终方案,后面有时间再继续研究吧。