是否有可能使 div 的高度达到可用区域的 100%?
我的设计有一个左侧栏,右侧有主要内容。在网站上的大多数页面上,左侧边栏比内容井高,但对于少数页面,内容井非常高,并且侧边栏处于浮动状态,没有底部。
我创建了一个糟糕的例子来说明我在这里所说的内容:
http://www.pmind .com/staging/pisspoor.html
我记得几年前,答案是只分配一个可以伪造的背景图像,即在我的示例中,只需制作一个左侧有一个绿色条的图像,然后使其成为主要红色 div 的背景。我知道网站通常希望拥有跨越 100% 浏览器窗口的区域,因此您可以使 HTML 和 BODY 为 100%,但在这种情况下,该区域由页眉和页脚限制,因此浏览器的尺寸不是一个因素,我只是希望绿色 div 是它的父红色 div 的高度。对于 CSS2.1 及更低版本来说,这仍然是一个白日梦吗?
I have a design that has a left side bar and a main content well on the right. On most pages on the site, the left sidebar is taller than the content well, but for a few pages, the content well is very tall and the sidebar is left floating with no bottom.
I have created a piss poor example of what I'm talking about here:
http://www.pmind.com/staging/pisspoor.html
I remember years ago the answer was to just assign a background image that would fake it, i.e. in my example just make an image that had a green bar down the left side of it and make that the background to the main red div. And I know this is a common want for websites to have areas that span 100% of the browser window, so you can make HTML and BODY be 100%, but in this case, the area is capped by the header and footer so the browser's dimensions aren't a factor, I just want the green div to be the height of it's parent red div. Is this still a pipe dream with CSS2.1 and lower?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Javascript 来完成这项工作,也可以在 CSS 中设置内容的最小高度:
You could use Javascript to do the job or you could set a min-height in CSS on the content:
这是 div 定位的一个很好的例子。这是一个工作示例 http://jsbin.com/izosi3
Here is a good example of div positioning. Here is a working example http://jsbin.com/izosi3