gpt4 book ai didi

html - 创建一个 DIV,填充可变高度标题下方的屏幕剩余部分

转载 作者:太空宇宙 更新时间:2023-11-04 12:18:22 24 4
gpt4 key购买 nike

我有一个标题,其高度可能会有所不同。页脚具有固定的高度。左侧和内容必须填满屏幕高度,左侧导航取固定宽度,内容取余数。

我该怎么做?到目前为止,我看到的每个可行的解决方案都具有固定的标题高度。

请只用 HTML 和 CSS,不要用 JS。

参见:JSFiddle example (下面完整复制的代码)

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type='text/css'>
* {
padding: 0;
margin: 0;
}
html, body{
overflow: hidden;
width: 100%;
height: 100%;
}
p {
line-height:1em;
}
ul {
margin-left : 2em;
list-style: none;
}
header {
width: 100%;
background-color:red;
border-bottom-width: 0.25em;
border-bottom-color: blue;
border-bottom-style: solid;
}
nav {
position:absolute;
width: 15em;
top:0;
left:0;
bottom:3.25em;
background-color:gray;
overflow:auto;
}
section {
position:absolute;
top:0;
left:15em;
bottom:3.25em;
right:0;
padding:0.25em;
background-color:yellow;
border-left-width: 0.25em;
border-left-color: blue;
border-left-style: solid;
overflow:auto;
}
footer {
position:absolute;
bottom:0;
width: 100%;
height: 3.25em;
text-align:center;
background-color:green;
}
</style>

</head>
<body>
<header>
<img src="http://www.luzchem.com/images/up1.jpg" style="vertical-align: top;" />
<p>Menu and Search</p>
</header>
<div style="position:relative; height:100%;">
<nav>
<ul>
<li><a href="#">Line 1</a>
</li>
<li><a href="#">Line 2</a>
</li>
<li><a href="#">Line 3</a>
</li>
</ul>
</nav>
<section>
<p>Body</p>
</section>
<footer>
<p>5509 Canotek RD, Unit 12, Ottawa Ontario, Canada, K1J9J9
<br />Phone: (613) 749-2442 Fax: (613) 749-2393 Toll Free: (800) 397-0977
<br /><a href="mailto:sales@luzchem.com?subject=General%20Inquiry&body=What%20do%20you%20want%20today%3F">sales@luzchem.com</a>
</p>
<div style="position:relative; bottom:0;"> <span style="text-align:right; float:right; margin-right:1em;">Copyright &copy; 2012 Luzchem Research Inc.</span>
<div style="text-align:left; float:left; margin-left:1em;"> <a href="company_info.php">Company Info</a>
<a href="">Link_2</a>
<a href="">Link_3</a>
</div>
</div>
</footer>
</div>
</body>
</html>

最佳答案

这里有一个可能的解决方案: https://jsfiddle.net/3zgvrde8/

HTML:

 <header>
<img src="http://www.luzchem.com/images/up1.jpg" style="vertical-align: top;" />
<p>Menu and Search</p>
</header>
<div style="position:relative; display:block;height:100%">
<nav>
<ul>
<li><a href="#">Line 1</a>
</li>
<li><a href="#">Line 2</a>
</li>
<li><a href="#">Line 3</a>
</li>
</ul>
</nav>
<section>
<p>Body</p>
</section>
</div>
<footer>
<p>5509 Canotek RD, Unit 12, Ottawa Ontario, Canada, K1J9J9
<br />Phone: (613) 749-2442 Fax: (613) 749-2393 Toll Free: (800) 397-0977
<br /><a href="mailto:sales@luzchem.com?subject=General%20Inquiry&body=What%20do%20you%20want%20today%3F">sales@luzchem.com</a>

</p>
<div style="position:relative; bottom:0;"> <span style="text-align:right; float:right; margin-right:1em;">Copyright &copy; 2012 Luzchem Research Inc.</span>

<div style="text-align:left; float:left; margin-left:1em;"> <a href="company_info.php">Company Info</a>
<a href="">Link_2</a>
<a href="">Link_3</a>

</div>
</div>
</footer>

CSS:

* {
padding: 0;
margin: 0;
}
html, body{
overflow: hidden;
width: 100%;
height: 100%;
}
p {
line-height:1em;
}
ul {
margin-left : 2em;
list-style: none;
}
header {
width: 100%;
background-color:red;
border-bottom-width: 0.25em;
border-bottom-color: blue;
border-bottom-style: solid;
}
nav {
top:0;
left:0;
bottom:3.25em;
background-color:gray;
float:left;
width: 15em;
display:block;
height:100%
}
section {
display:block;
left:15em;
padding:0.25em;
background-color:yellow;
border-left-width: 0.25em;
border-left-color: blue;
border-left-style: solid;
overflow:auto;
width: 100%;
height:100%
}
footer {
clear:both;
bottom:0;
width: 100%;
height: 3.25em;
text-align:center;
background-color:green;
position:absolute;
}

我建议将您的页脚与其他内容分开并定位,以便它绝对位于底部。然后使用您的左侧导航和内容,以固定宽度 float 导航,以便您可以相应地安排您的正确内容 - 无需在此处使用绝对定位,因为它们没有固定高度,也没有定位,因为您的标题高度可变。

希望对您有所帮助。

关于html - 创建一个 DIV,填充可变高度标题下方的屏幕剩余部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28533997/

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