gpt4 book ai didi

cross-browser - 具有相同高度但拉伸(stretch)到最小高度为 100% 的 2 列的纯 CSS

转载 作者:行者123 更新时间:2023-11-28 18:22:04 31 4
gpt4 key购买 nike

我正在为我的网络应用制作模板。它应该有页眉、页脚、正文和带有渐变背景的侧边菜单。从 800x600 开始,该页面在任何分辨率下都应该看起来相似,因此我使用百分比而不是固定大小。此外,它应该在 IE7/8 中工作,所以我试图避免 CSS3 和 webkit/gecko 的唯一功能

因为正文内容可能会超过屏幕大小,所以我使用 this保持列高度相同的方法。

我面临的问题是:当正文内容小于屏幕且不需要滚动时,希望列的背景填充 100% 的可用视口(viewport),不包括页眉和页脚。

我认为自己更像是一个 Java 人而不是网页设计师,所以我不太确定在 CSS 方面我在做什么,但我已经尝试过 this没有结果。有没有不用 javascript 就能实现我的目标的方法?

这是我的代码。尽管我在问这个问题之前努力清理它,但由于我一直在测试的所有更改,它可能看起来不干净。

CSS

* {
margin-top: 0;
margin-bottom:0;
}

html, body {
height: 100%;
margin: 0;
padding: 0;
background-color: rgb(216, 218, 234);
}

#container {
width: 80%;
min-height: 100%;
height: 100%;
margin-left: 10%;
margin-right: 10%;
background-color: rgb(255, 255, 204);
}

#header {
min-height:120px;
height: 19%;
width: 100%;
background-color: #CCC;
clear: both;
float: left;
}

#subcontainer {
clear: both;
min-height: 77%;
height: auto !important;
height: 100%;
background-color: rgb(255, 255, 204);
position: relative;
}

#menuback {
float: left;
width: 100%;
min-height: 100%;
position:relative;
right:85%;
background: #088316;
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#088316), to(#FFFFFF));
background: -webkit-linear-gradient(#088316, #FFFFFF);
background: -moz-linear-gradient(#088316, #FFFFFF);
background: -ms-linear-gradient(#088316, #FFFFFF);
background: -o-linear-gradient(#088316, #FFFFFF);
background: linear-gradient(#088316, #FFFFFF);
-pie-background: linear-gradient(#088316, #FFFFFF);
behavior: url(/pie/PIE.htc);

}

#menu {
float: left;
width: 15%;
min-height:100%;
position:relative;
left:85%;
}

#fondocuerpo {
float: left;
width: 100%;
min-height:100%;
overflow:hidden;
position:relative;
background-color: #DDF;
}

#cuerpo {
float: left;
width: 85%;
min-height:100%;
position:relative;
left:85%;

}

#footer {
clear:both;
width: 100%;
height:4%;
background: #007F0E;
}

HTML

<body>
<div id="container">
<div id="header">
<p>Header</p>
</div>
<div id="subcontainer">
<div id="fondocuerpo">
<div id="menuback">
<div id="menu">
&nbsp;
<p>Menu</p>
</div>
<div id="cuerpo">
<p>body</p>
<p>body</p>
<p>body</p>
</div>
</div>
</div>
</div>
<div id="footer">
<p>Footer</p>
</div>
</div>
</body>

this当内容小于视口(viewport)时它应该如何表现。

最佳答案

这是我能得到的最接近的。它应该在 ie8+ 中工作,但我不太确定 ie7,因为我没有可以测试它的浏览器。

我已经使用了固定高度的页眉和页脚,因为我认为如果内容大于百分比大小,它会导致模板损坏

HTML

<div id="wrapper">
<div id="header">header text</div>
<div id="leftColumn"></div>
<div id="rightColumn"></div>
<div id="footer">footer text</div>
</div>

CSS

html, 
body {min-height:100%; padding:0; margin:0;}
#wrapper {padding:50px 0; position:absolute; top:0; bottom:0; left:0; right:0;}
#leftColumn,
#rightColumn {min-height:100%; float:left; width:50%;}
#header {margin-top:-50px; height:50px;}
#footer {clear:both; margin-bottom:-50px; height:50px;}

http://jsfiddle.net/naqE6/33/

这个解决方案不是很好,虽然一列比初始窗口高度高,但另一列由于某种原因没有增长。

由于您的解决方案需要与 IE7 兼容并且没有纯 css 解决方案,我会使用简单的 jquery:

http://jsfiddle.net/naqE6/36/

关于cross-browser - 具有相同高度但拉伸(stretch)到最小高度为 100% 的 2 列的纯 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16610506/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com