当扩展其他div
时,背景不覆盖100vh
的问题通常是由于CSS样式设置不当导致的。以下是一些基础概念和相关解决方案:
100vh
表示视口高度的100%,即浏览器窗口的高度。100vh
,子元素的背景可能不会覆盖整个视口。以下是一些常见的解决方案示例:
100vh
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
}
.container {
height: 100vh;
background-color: lightblue;
}
.child {
height: 200px; /* 示例高度 */
background-color: lightcoral;
}
</style>
</head>
<body>
<div class="container">
<div class="child"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
}
.container {
display: flex;
flex-direction: column;
height: 100vh;
background-color: lightblue;
}
.child {
flex-grow: 1;
background-color: lightcoral;
}
</style>
</head>
<body>
<div class="container">
<div class="child"></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
}
.container {
height: 100vh;
background-color: lightblue;
overflow: auto; /* 清除浮动 */
}
.child {
float: left;
width: 100%;
height: 200px; /* 示例高度 */
background-color: lightcoral;
}
</style>
</head>
<body>
<div class="container">
<div class="child"></div>
</div>
</body>
</html>
通过以上方法,可以有效解决扩展其他div
时背景不覆盖100vh
的问题。根据具体需求选择合适的解决方案即可。
领取专属 10元无门槛券
手把手带您无忧上云