Home > Web Front-end > HTML Tutorial > margin并不能够扩大父元素的尺寸_html/css_WEB-ITnose

margin并不能够扩大父元素的尺寸_html/css_WEB-ITnose

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

margin并不能够扩大父元素的尺寸:
很多初学者以为设置margin外边距能够撑开父元素,其实并不是这样的。
代码如下:

 

<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">#main{  width:600px;  height:400px;  margin:0 auto;  background:green;}#inner{  width:50px;  height:50px;  background:#eee;  margin-left:600px;}</style></span></head><body><div id="main">  <div id="inner"></div></div></body></html>
Copy after login

 

上面的代码演示可以看出,内部的子元素只是飞出了父元素,并不会扩大父元素的尺寸,但是如果这个时候给父元素添加overflow:hidden话,子元素会被隐藏。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=14629

更多内容可以参阅:http://www.softwhy.com/divcss/

 

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