margin的BUG(2)_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:15:03
Original
918 people have browsed it

      继续上一次的学习,这次又发现了margin的第二个bug.既当同时对两个相邻的div盒子设置margin时,他们之间的间隙不能正常显示.

    具体表述为:先建立两个div1和div2

<div class="div1"></div><div class="div2"></div>
Copy after login

div2设置成margin-top,div1设置margin-bottom,代码如下:

.div1{    width: 200px;height: 200px;    background: green;    margin-bottom: 50px;  }  .div2{    width: 200px;height: 200px;    background: blue;    margin-top: 80px;  }
Copy after login

设置背景色和宽高,是为了方便比对观察

那么两者之间的间隙会变成margin-top和margin-bottom比较出来的最大值.

如果真想要间隙进行相加,则应把div2元素变为inline-block,代码如下:

.div2{    width: 200px;height: 200px;    background: blue;    margin-top: 80px;    display:inline-block;  }
Copy after login

 将div2转换为内联块属性后,两者之间的间隙就能正常相加而正确显示了.

 

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!