盒子模型塌陷解决办法
一、什么叫盒子模型塌陷
- 当子元素设置外边距,导致父元素连带向下,就会导致盒子模型塌陷。
- 例如这种情况:
<style>*{margin: 0;padding: 0;}.box{width: 100px;height: 100px;background-color: tomato;}#btn{margin-top: 20px;} </style> <div class="box"><div id="btn">容器</div> </div>
二、解决盒子模型塌陷的方法:
1.给父容器设置上边线
border-top: 1px solid transparent;
.box{width: 100px;height: 100px;background-color: tomato;border-top: 1px solid transparent;}
2.给父元素设置内边距
padding: 1px;
.box{width: 100px;height: 100px;background-color: tomato;padding: 1px;}
3.给父元素设置超出部分隐藏属性
overflow: hidden;
.box{width: 100px;height: 100px;background-color: tomato;overflow: hidden;}
原文地址:https://blog.csdn.net/qq_45806781/article/details/109297487
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 809451989@qq.com 进行投诉反馈,一经查实,立即处理!