gpt4 book ai didi

html - 如何在不超出窗口高度的情况下将标题添加到可独立滚动的 div?

转载 作者:行者123 更新时间:2023-11-28 00:14:14 26 4
gpt4 key购买 nike

我找到了另一篇文章,它让我非常接近我正在寻找的东西,但不是所有的方式。(http://stackoverflow.com/questions/10474354/layout-with-fixed-header-and-footer-fixed-width-sidebar-and-flexible-content)

本质上,我想为每个可滚动区域添加一个页眉/标题部分。这些不应在各自的部分内滚动。这是 jsfiddle,我已经注释掉了标题部分。添加它们时,它会将 div 推到窗口的高度之外,从而扩展内容。感谢您的帮助!

原始代码如下:

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Application Wireframe</title>
<style type="text/css">
body {
margin: 0;
height: 100%;
}

#header {
text-align: left;
background: #4f0f00;
color: #fff;
width: 100%;
margin: 0 0 0 0;
border: 0;
overflow: hidden;
position: fixed;
}
#accountbar {
background-color: #000000;
color: white;
height: 40px;
width: 100%;
}


#contextbar {
position:fixed;
top:40px;
width: 100%;
}
#leftheader {
background-color: #66CCFF;
height: 40px;
width:200px;
float:left;
}
#contentheader {
background-color: #996600;
color: white;
height: 40px;
}

#middle {
position:fixed;
top:80px;
width: 100%;
height: 100%;
}

#left_col {
float: left;
width: 200px;
/*height: 100%;*/
}
#left_col_wrap {
/*width: 100%;
height: 100%;
position: fixed;*/
}
#leftnav {
background-color: #66FFFF;
height: 100%;
overflow: scroll;
/*width: 200px;*/
}

#main_col {
/*margin-left: 200px;*/
/*height: 100%;*/
}
#main_content_wrap {
/*position:fixed;
width:100%;
height: 100%;*/
}
#messagegap {
background-color: white;
}
#contentpane {
background-color: #FFAA00;
height: 100%;
overflow: scroll;
}
#contentfoot {
background-color: #C80;
height: 20px;
position: fixed;
width: 100%;
bottom: 0;
padding-bottom: 18px;
}
#footer {
background-color: #CCCCCC;
clear: left;
width: 100%;
position: fixed;
bottom: 0;
}
</style>
</head>
<body>
<div id="header">
<div id="accountbar"><b>Account Bar</b> -always visible-this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this</div>
</div>
<div id="contextbar">
<div id="leftheader"><b>Left Header</b></br>-usually says "Contents"-</div>
<div id="contentheader"><b>Content Header</b> -always visible- this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this</div>
</div>
<div id="middle">
<div id="left_col">
<div id="left_col_wrap">
<div id="leftnav"><b>Left Navigation</b>
<ul>
<p>
First</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
Last</p>
</ul>
</div>
</div>
</div>
<div id="main_col">

<div id="main_content_wrap">
<div id="contentpane"><b>Content Pane</b>
<p>Content Pane</b> -always visible- this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this</p>
<ul>
<p>
First</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
Last</p>
</ul>
</div>
</div>
</div>
</div>
<div id="footer"><b>Footer</b> -always visible, always at bottom of window-</div>
</body>
</html>

解决方法如下:

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Application Wireframe</title>
<style type="text/css">
body {
margin: 0;
height: 100%;
}

#header {
text-align: left;
background: #4f0f00;
color: #fff;
width: 100%;
margin: 0 0 0 0;
border: 0;
overflow: hidden;
position: fixed;
}
#accountbar {
background-color: #000000;
color: white;
height: 40px;
width: 100%;
}


#contextbar {
position:fixed;
top:40px;
width: 100%;
}
#leftheader {
background-color: #66CCFF;
height: 40px;
width:200px;
float:left;
}
#contentheader {
background-color: #996600;
color: white;
height: 40px;
}

#middle {
position:absolute;
top:80px;
width: 100%;
overflow-y: visible;
bottom: 8px;
/*height: 100%;*/
}

#left_col {
float: left;
width: 200px;
/*height: 100%;*/
}
#left_col_wrap {
/*width: 100%;
height: 100%;
position: fixed;*/
}
#leftnav {
background-color: #66FFFF;
height: 100%;
overflow: scroll;
/*width: 200px;*/
}

#main_col {
/*margin-left: 200px;*/
/*height: 100%;*/
}
#main_content_wrap {
/*position:fixed;
width:100%;
height: 100%;*/
}
#messagegap {
background-color: white;
}
#contentpane {
background-color: #FFAA00;
height: 100%;
overflow: scroll;
}
#contentfoot {
background-color: #C80;
height: 20px;
position: fixed;
width: 100%;
bottom: 0;
padding-bottom: 18px;
}



#footer {
background-color: #CCCCCC;
clear: left;
width: 100%;
position: fixed;
bottom: 0;
}

</style>
</head>
<body>
<div id="header">
<div id="accountbar"><b>Account Bar</b> -always visible-this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this</div>
</div>
<div id="contextbar">
<div id="leftheader"><b>Left Header</b></br>-usually says "Contents"-</div>
<div id="contentheader"><b>Content Header</b> -always visible- this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this</div>
</div>
<div id="middle">
<div id="left_col">
<div id="left_col_wrap">
<div id="leftnav"><b>Left Navigation</b>
<ul>
<p>
First</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
Last</p>
</ul>
</div>
</div>
</div>
<div id="main_col">
<div id="main_content_wrap">
<div id="contentpane"><b>Content Pane</b>
<p>Content Pane</b> -always visible- this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this this is the main page -- everyone else stay thin so we can see this</p>
<ul>
<p>
First</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
left</p>
<p>
Last</p>
</ul>
</div>
</div>
</div>
</div>
<div id="footer"><b>Footer</b> -always visible, always at bottom of window-</div>
</body>
</html>

最佳答案

为此你需要使用 position: fixed; 我想你正在寻找这个。

HTML:

<div id="header">  Header Content    </div>

<div id="wrapper">

<div id="leftheader"> Left Header </div>

<div id="leftwrapper">
---CONTENT HERE---
</div>

<div id="rightheader"> Right Header </div>

<div id="rightwrapper">
---CONTENT HERE---
</div>
</div>

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

CSS:

<style type="text/css">
div#header
{position: fixed;left: 0px;top: 0px;height:100px;width:100%;background: black;color: White; }

div#leftheader
{position: fixed;left: 0px;top: 100px; height: 50px;width: 30%;float: left; background: red; color: White; }

div#leftwrapper
{position: fixed;left: 0px;color: Maroon;margin-top: 150px;margin-left: 0;margin-bottom: 100px; width: 30%; min-width: 30%; height: 600px; max-height: 600px; overflow-y: auto; }

div#rightheader
{position: fixed;left: 0px;top: 100px; height: 50px;width: 70%;margin-left: 30%;float: right;background: green;color: White;}

div#rightwrapper
{position: fixed;left: 0px;color: Purple;margin-left: 30%;margin-top: 150px;margin-bottom: 100px;width: 70%; min-width: 70%;height: 500px;max-height: 500px;overflow-y: auto; }

/*div#wrapper
{ height: 1000px; }*/

div#footer
{position: fixed;left: 0px;bottom: 0px; height: 100px;width: 100%;background: black;color: White;}
</style>

注意:我只在 Firefox 中测试过。

希望对你有所帮助。谢谢并继续发帖。

干杯。 !!

关于html - 如何在不超出窗口高度的情况下将标题添加到可独立滚动的 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13206116/

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