Heim  >  Artikel  >  Web-Frontend  >  为什么父div没有被撑开_html/css_WEB-ITnose

为什么父div没有被撑开_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:241135Durchsuche

为什么父div没有被撑开:

在正常情况下,如果父对象没有设置高度,子对象能够将子对象撑开,但是如果子对象浮动且没有清除浮动的话,在IE8或者FF浏览器,父对象并不能够被撑开,在IE6下可以撑开。

代码实例: 

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.51texiao.cn/" /><title>蚂蚁部落</title><style type="text/css">.parent{  border:1px solid red;  width:500px;}.first,.second{  float:left;  height:100px;  width:100px;  border:1px solid blue}</style></head><body><div class="parent">  <div class="first"></div>  <div class="second"></div></div></body></html>

以上代码在IE6下可以撑开父div,但是在IE8或者FF浏览器下不能够被撑开。解决方法就是清除浮动。代码如下: 

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.51texiao.cn/" /><title>蚂蚁部落</title><style type="text/css">.parent{  border:1px solid red;  width:500px;  overflow:hidden}.first,.second{  float:left;  height:100px;  width:100px;  border:1px solid blue}</style></head><body><div class="parent">  <div class="first"></div>  <div class="second"></div></div></body></html>

原文地址是:http://www.51texiao.cn/div_cssjiaocheng/2015/0519/1891.html

最原始地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4699

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn