zoukankan      html  css  js  c++  java
  • margin-top 为什么会影响父元素的 margin-top

     1.原因:

     In this specification, the expression collapsing margins means that adjoining margins (no non-empty content, padding or border areas or clearance separate them) of two or more boxes (which may be next to one another or nested) combine to form a single margin.

    ----所有毗邻的两个或更多盒元素的margin将会合并为一个margin共享之。毗邻的定义为:同级或者嵌套的盒元素,并且它们之间没有非空内容、 Padding或Border分隔。

    2.解决方法:

      1、修改父元素的高度,增加padding-top样式模拟(padding-top:1px;常用)
      2、为父元素添加overflow:hidden;样式即可(完美)
      3、为父元素或者子元素声明浮动(float:left;可用)
      4、为父元素添加border(border:1px solid transparent可用)
      5、为父元素或者子元素声明绝对定位

  • 相关阅读:
    Mysql数据查询
    Mysql数据类型
    desc和show
    Mysql权限管理
    深入理解inode和硬链接和软连接和挂载点
    Linux用户和组
    VIM文本编辑器
    Linux文件操作
    MySQL基础
    八大排序
  • 原文地址:https://www.cnblogs.com/zouqin/p/5473277.html
Copyright © 2011-2022 走看看