html - DIV 在 IE7、IE8 和 IE9 中不扩展

标签 html css

我使用了四个 DIV:容器、页眉、内容和页脚。

基于文本或图像,内容 DIV 已展开,但页眉和页脚 div 在 IE7、IE8 和 IE9 中未展开,但在 Firefox、IE10 中工作正常和 IE11。

HTML:

<div id="container">
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
</div>

CSS

<style>
body {
    height:100%;
    margin-left: 0;
    margin-top: 0;
    padding:0;
    width:100%;
    position: relative;
    display:inline-block;
}

#header {
    top:0px;
    height:75px;
    width:100%;
}

#container {
    display:table;
    width:100%;
    height:100%;
}

#content {
    width:100%;
    height:auto;
}

#footer {
    top:5px;
    bottom:0px;
    height:45px;
    width:100%;
}
</style>

有什么想法吗?

最佳答案

footerheader 有固定值

#footer
{
    top:5px;
    bottom:0px;
    /*height:45px;*/
    width:100%;
}
#header
{
    top:0px;
    /*height:75px;*/
    width:100%;
}

当它有固定值时,元素不会扩展。 min-height 可能是一个简单的解决方案,但不支持 CSS2.0 的浏览器将无法正确处理它,并可能给您带来意想不到的结果。


答案已更新...

我给你一个你可能已经预料到的答案。我仍然不知道你想要实现什么,你需要什么样的布局,等等。但是我大胆地猜测,我调整了这段代码。如果您想要的是使 headerfooter 响应 content div,这将是您的确切答案。

body {
  margin-left: 0;
  margin-top: 0;
  padding:0;
}

#header {
  top:0px;
  width:100%;
  height:75px;
  position:absolute;
  background-color:#eaeaea;
}

#content {
  display:table;
  padding:75px 0 45px;
  height:150px;
  position:relative;
}

#footer {
  bottom:0px;
  width:100%;
  height:45px;
  position:absolute;
  background-color:#1d1d1d;
}
<!DOCTYPE html>	
<html>
	<head>
	</head>
	<body>

		<div id="content">
            
            <h3>Expanding as you expected....</h3>
            <h5>
                * Try remove these h3 and h5 element. <br/>
              the result will be nothing on your screen because no dimension is given to content div.
            </h5>
			<div id="header"></div>
			<div id="footer"></div>
		</div>
	</body>
</html>

尝试查看上面的代码结果并测试它如何随着 content div 变小或变大而扩展。

关于html - DIV 在 IE7、IE8 和 IE9 中不扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29912910/

相关文章:

javascript - 将 href 链接重定向到外部应用程序

html - 背景大小之间的差异 :cover and background-size:contain

javascript - 避免关注 html-table 中的链接

html - 将元素放在居中元素旁边

css - <a> 按钮上的按钮按下效果

html - 如何仅使用 CSS 和 HTML 制作返回顶部按钮?

javascript - 向我的图像 slider 添加过渡效果

html - 位置 html/css

php - IE 中的下拉菜单对抗 FF 和 Chrome

html - Angular5 mat-menu修改填充和宽度属性?