我有一个设置为position:fixed的div,它是我的菜单容器。我将其设置为top:0px,bottom:0px以始终填充视口。在该div内,我想要有另外两个div,其中较低的一个包含许多行并具有overflow:auto属性。我期望它应该被包含在容器div中,但如果行数过多,则会将其扩展到固定的div之外。下面是我的代码和截图以进行澄清:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MyPlan</title>
<meta name="X-UA-COMPATIBLE" value="IE=8" />
<style type="text/css">
#outerfixed { position:fixed; width:200px; background-color:blue; padding:5px; top:0px; bottom:30px;}
#innerstatic1 { width:100%; background-color:yellow; height:100px;}
#innerstatic2 { overflow:auto; background-color:red; width:100%;}
</style>
</head>
<body>
<div id="outerfixed">
<h3>OUTERFIXED</h3>
<div id="innerstatic1">
<h3>INNERSTATIC1</h3>
</div>
<div id="innerstatic2">
<h3>INNERSTATIC2</h3>
line<br />
...lots of lines
line<br />
</div>
</div>
</body>
</html>
有没有办法让我做到这一点?我想让 #innerstatic2 很好地包含在 #outerfixed 中,如果它比 #outerfixed 内部拥有的空间更大,那么就出现滚动条。
我知道有一些通过修复 #innerstatic2 来绕过此问题的可能性,但如果可能的话,我真的希望它在 #outerfixed 内部的流程中,这样如果我将 #outerfixed 移动到其他位置,则内部元素也会随之移动。
编辑:我知道我可以在 #outerfixed 上设置 overflow:auto 并在整个元素上获得滚动条,但是我特别想在 #innerstatic2 上仅获得滚动条,因为它是一个网格,我只想滚动网格。
有人知道吗?可行吗?
overflow: hidden
添加到#outerfixed
的 css 中,但不幸的是这看起来不太美观。 - David Thomasoverflow-y: auto;
就足够了,因此当内容在#innerstatic2
中超过最大高度时,滚动条将呈现,但并不总是,这很丑陋。那正是我所需要的。您可以检查http://climaenruta.lhdevsolutions.net/左侧边栏中的`#searchContainer`。 - Juan Ignacio Avendaño Huergo