gpt4 book ai didi

css - 流体垂直布局

转载 作者:行者123 更新时间:2023-11-28 08:43:18 25 4
gpt4 key购买 nike

我搜索了很多论坛和问题,但找不到任何关于流体垂直(不是水平布局)的内容。

我有如下标记:

<div class="wrapper">
<div class="header"></div>
<div id="content"></div>
<div class="footer"></div>
</div>

我的 CSS:

html,body {margin: 0; padding: 0; height: 100%;}
.wrapper {width: 900px; margin: 0 auto; height:auto !important; height:100%; min-height:100%; position: relative;}
#content {padding-bottom: 60px; /* For the footer padding */ }
.footer { position: absolute; bottom: 15px; height: 45px;}

在这种情况下,我的布局具有固定高度的页眉和内容。页脚粘在底部。

一切都很好,但我想制作流畅的垂直布局,以便页脚始终贴在底部(就像现在一样),但页眉和内容具有流畅的高度:相应地为 30% 和 70%。

我怎样才能做到这一点?

最佳答案

布局:

<body>
<div id="container">
<div id="header">
</div>

<div id="content">
<div id="content-text">
</div>
</div>

<div id="footer">
</div>

</div>
</body>
</html>

CSS:

html {
height: 100%;
}

body {
padding: 0;
margin: 0;
height: 100%;
}

#container {
position:relative;
z-index:1;
width:100%;
height:100%;
margin-left: auto;
margin-right:auto;
overflow:hidden;
}

#header,
#footer {
position:absolute;
left:0;
z-index:2;
width:100%;
overflow:hidden;
}

#header {
top:0;
height:30%;
}

#footer {
bottom:0;
height:1.6em;
}

#content {
position:absolute;
bottom:0;
top:0;
right:0;
left:0;
z-index:10;
width: 100%;
height:auto;
margin-top:30%;
margin-bottom:1.6em;
overflow:hidden;
}

#content-text {
position:relative;
width:100%;
height:100%;
margin-left: auto;
margin-right:auto;
overflow:auto;
}

我还建议在此之前重置 CSS。

编辑抱歉,首先我为标题添加了修复大小,我更正了它,尽管这样看起来有点错误。我仍在寻找最佳方法。

关于css - 流体垂直布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8119012/

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