gpt4 book ai didi

html - CSS 高度 - 2 个 div 之间为 100%

转载 作者:行者123 更新时间:2023-11-28 10:24:30 25 4
gpt4 key购买 nike

我正在开发 CSS3/HTML5 Asp.NET 4.5 网络应用程序。我的 HTML 和 CSS 按照我想要的方式用于我的布局,除了一个问题。

我的 css 背后的理论是页眉和导航显然设置在页面顶部,带有一个带有旁边和文章的容器,然后是一个独立的页脚,我希望它始终位于页面底部,无论如何内容有多么少。一切正常,除了当我将 aside 设置为 100% 高度时,它是视口(viewport)高度的 100%,这意味着在内容很少的页面上,你必须滚动 260px(页眉、导航和页脚的组合高度)看见了。因此,为了解决这个问题,我将边距设置为顶部 280px,底部 80px,认为这样就可以了。它没。所以我开始玩 position and clear 正如 SO 和网络上类似问题所建议的那样,但没有成功。

HTML:

<body>
<form id="form1" runat="server">
<header>
<div id="logo">
</div>
<div id="title">
<h1>Nathan A. Chesebro</h1>
<h2>United States Merchant Marine</h2>
</div>
</header>
<nav>

</nav>
<div id="content">
<aside>
Vessel data
</aside>
<article>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</article>
</div>
<footer>

</footer>
</form>
</body>

CSS

* 
{
margin: 0;
}
body
{
margin: 0px auto;
height: 100%;
}

form, html
{
height: 100%;
}

header
{
margin: 0px auto;
background-color: #1041a2;
background-image: url(../Images/headerHCJ.png);
background-repeat: no-repeat;
background-position-x: right;
height: 150px;
position: relative;
}

nav
{
background-image: url(../Images/nav.png);
font-family: Arial;
color: white;
background-repeat: repeat-x;
height: 30px;
width: 100%;
line-height: 30px;
margin: 0px auto;

}

#content
{
margin: 0px auto;
height: 100%;
}

aside
{
margin: 180px 0px 80px 0px auto;
float: left;
width: 250px;
background-color: gray;
height: 100%;
overflow: hidden;
position: relative;
clear: both;
}

article
{
margin: 0px auto;
padding-left: 250px;
min-height: 100%;
}

footer {
height:80px;
background: black;
clear: both;
}

最佳答案

这是您要找的吗?这只是一个概念,所以我没有复制您的确切代码。另外,我在 CSS 中使用了 calc() 方法(它得到越来越多的浏览器支持,但可能仍然对某些浏览器有限制,例如 opera-mini 等)。

这是 fiddle :http://jsfiddle.net/thePav/A3NCW/1/

CSS

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

header {height: 150px; background-color: #800}
header #logo {}
header #title {}

nav {height: 30px; background-color: #080}

#content {overflow: hidden; height: calc(100% - 280px)}
#content aside {background-color: #555; height: 100%; float: left; width: 25%}
#content article {float: left; width: 75%}

#footer {width: 100%; height: 100px; position: absolute; bottom: 0; left: 0; background-color: #000}

HTML

<header>
<div id="logo"></div>
<div id="title"></div>
</header>

<nav></nav>

<div id="content">
<aside></aside>
<article>Some content here</article>
</div>

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

关于html - CSS 高度 - 2 个 div 之间为 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23794139/

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