- 作者:霏梦
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>浮动元素的高度塌陷与解决方案</title>
<style>
.container {
border: 3px solid red;
}
.item {
width: 150px;
height: 150px;
float: left;
}
.item:first-of-type {
background-color: lightgreen;
}
.item:nth-last-of-type(2) {
background-color: lightsalmon;
}
.item:last-of-type {
background-color: magenta;
}
.container {
overflow: auto;
overflow: hidden;
}
</style>
</head>
<body>
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</body>
</html>