关于margin-top溢出父节点元素的处理方法

来源:互联网 发布:js源代码加密 编辑:程序博客网 时间:2024/06/09 04:13

给子元素margin-top时,若这个子元素前面没有其他内容,这个margin-top值会应用到父元素上

解决方案,给父元素设置:before

#content{height: 80px;width: 100%;background: red;}#header{height: 60px;width: 100%;background: blue;margin-top: 20px;}#content:before{                      content: "";                      display: table;                  }


0 0