子元素增加margin-top会增加给父元素的问题_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:29:33
Original
1535 people have browsed it

假设我们有如下代码

  


    

  

会发现效果如下所示

子元素的margin-top并没有使子元素与父元素分开,反倒效果等同于给父元素加了一个margin-top;

解决的方法也有,具体为:

1.修改父元素的高度,增加padding-top样式模拟(padding-top:1px;)

2.为父元素添加overflow:hidden;

3.为父元素或者子元素生命元素浮动(float:left;可用但是不推荐)

4.为父元素添加border(border:1px solid transparent)

5.为父元素或者子元素声明绝对定位

6.给父元素增加内容生成#father:before{content:' ';display:table};

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template