Home  >  Article  >  Web Front-end  >  父div没有被撑开,该怎么解决?_html/css_WEB-ITnose

父div没有被撑开,该怎么解决?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:22:202154browse

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />	<title></title>	<style type="text/css">		html, body {			width: 100%;			height: 100%;			margin: 0px;			padding: 0px;		}		#div1 {			width: 80%;			height:100%;			margin: 0px auto;			padding: 0px;			background-color: #b0ffdd;		}	</style></head><body>	<div id="div1">		<div id="div2" style="width: 90%; height: 1200px; background-color: #dcb1ef; margin: 0px auto;">		</div>	</div></body></html>


上面的例子中,保留div1的height:100%的前提下,能够让div2撑开div1吗?


回复讨论(解决方案)

默认情况下就是撑开的

 height:100%;不要或者设为 height:auto,

都100%了。。。你还想怎么撑开,,,本身就是撑开了的。。。

不能的,height:100%是当前窗口的高度,#div1 height:auto;

设定height:auto;的话div1内部就不能使用百分比设定高度了。

实际应用中div2高度不确定,而且可能会用百分比设定高度。希望的效果是div2较小的场合,div1充满屏幕;div2较大的场合,div1被撑开和div2一样大。

你需要的是设置  min-height:100

原先设定是#div1 min-height:100%;,能实现期待效果,但div1内部元素高度不能用百分比布局了,所以想修改。

目前的困境是,如果设定height:100%就撑不开;不设定内部元素布局又受影响。

在怀疑单纯CSS是不是做不到?

吧 #div 下面需要百分比布局的 元素 拿出来
 另外弄一个 div.height:100% 的层  这个层  和 #div 重叠 就可以了(前面拿出来的元素放进去)

另外放div好像还是难以达到效果。

div设定高度(不是auto)的情况下,没办法被子元素撑开吗?以前在ie6似乎是撑开的

Statement:
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