批改状态:合格
老师批语:总得来说写的非常不错,继续加油!
<!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: 2px dashed red;}.item {width: 100px;height: 100px;background-color: greenyellow;}.item {float: left;}</style></head><body><div class="container"><div class="item"></div></div></body></html>

container的高度没了 边框线成了一条线overflow: hidden/auto
<!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: 2px dashed red;}.item {width: 100px;height: 100px;background-color: greenyellow;}.item {float: left;}/* 1.给父元素设置指定高度 *//* .container {height: 100px;} *//* 2.给父元素设置浮动 *//* .container {float: left;} *//* 3.添加兄弟元素清浮动 *//* .clear {clear: both;} *//* 4.添加伪元素清浮动 *//* .container::after {content: "";display: block;clear: both;} *//* 5.设置父元素的overflow=hidden/auto属性 */.container {/* overflow: hidden; */overflow: auto;}</style></head><body><div class="container"><div class="item"></div><!-- <div class="clear"></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>三列经典布局</title><style>* {margin: 50px auto;padding: 0;box-sizing: border-box;text-align: center;}</style></head><body><div class="container"><div class="item1">左边</div><div class="item2">中间</div><div class="item3">右边</div></div></body></html>
.container {width: 800px;min-height: 300px;position: relative;}.container > .item1 {background-color: lightcoral;width: 100px;height: 300px;position: absolute;top: 0;left: 0;}.container > .item3 {background-color: lightcoral;width: 100px;height: 300px;position: absolute;top: 0;right: 0;}.container > .item2 {background-color: lightgreen;width: 600px;height: 300px;position: absolute;top: 0;left: 100px;}
.container {width: 800px;min-height: 300px;overflow: hidden;}.container > .item1 {width: 100px;height: 300px;background-color: lightpink;float: left;}.container > .item2 {width: 600px;height: 300px;background-color: lightblue;float: left;}.container > .item3 {width: 100px;height: 300px;background-color: lightpink;float: right;}

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号