margin的应用及影响范围
n 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分隔。
因为嵌套也属于毗邻,所以在样式表中优先级更高的 .show h2
的margin覆盖了之前外层div定义的margin,导致最终整个div产生10px的间距。
margin:0px auto”,表示外边距上下为0,左右相等距离居中。
资料参考 https://www.jb51.net/css/75789.html父元素与子元素之间的margin-top问题(css hack)