如何使用 div/css 创建两帧水平平铺框架集的行为?
我正在尝试布局这样的网页:
|-----------------------|
| header (fixed) | <- no scroll bar
|-----------------------|
| body | |
| | |
| | | <- scroll bar
| | |
| | |
| | |
| | |
| ... continues ... | |
| ... so requires ... | |
| ... scroll bar ... | |
|---------------------|-|
在过去,我会使用框架集来完成此操作。由于某些原因(包括它已被弃用),我不想走这条路。
在过去,我以为我是使用 height=100% 的表格来完成此操作,其中两行作为页面的整个主体,并且溢出样式在不同的位置设置为隐藏/自动以使底行到达有主页内容的滚动条。我可以接受这个作为解决方案,但我不记得如何正确设置它(我很确定它涉及将正确的页面元素设置为位置:相对或其他东西,但我一直在敲打我在键盘上花了两个小时试图让它工作,所以我放弃了)。
我读过声称可以使用框架/表格执行的任何操作都可以使用正确的 div 和 css 执行,所以我真的很希望看到有人向我展示该解决方案。
另请注意:我只希望滚动条在需要时根据内容显示(根据溢出:自动),而不是始终显示(溢出:滚动)。
I'm trying to lay out a web page like this:
|-----------------------|
| header (fixed) | <- no scroll bar
|-----------------------|
| body | |
| | |
| | | <- scroll bar
| | |
| | |
| | |
| | |
| ... continues ... | |
| ... so requires ... | |
| ... scroll bar ... | |
|---------------------|-|
In the old old days I'd have done this with a frameset. I don't want to go that route for a few reasons (including it being deprecated).
In the not-as-old days I thought I'd done this using a height=100% table with two rows as the entire body of the page, and the overflow style set hidden/auto in different places to get the bottom row to have the scroll bar for the main page content. I'd be OK with this as a solution, but I can't remember how to set it up right (I'm pretty sure it involves getting the right page elements set to position:relative or something, but I've been banging my head on the keyboard for two hours trying to get it to work so I give up).
I've read claims that anything you can do with frames/tables you can do with the right divs and css, so I'd really like to see someone show me that solution.
Also note: I only want the scroll bar to appear when needed based on the content (as per overflow:auto) not all the time (overflow:scroll).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个完全可行的解决方案,可以解决您的问题,即在绝对定位的标题下滚动内容,而浏览器窗口上没有其他滚动条。
Here is a fully working solution to your problem scrollable content under an absolute positioned header with no other scrollbar on the browser window.
这是制作固定页眉的简单方法,当您还想制作固定页脚时,它会变得有点复杂。不过这应该对你有用。
这个好一点,我们只需要去掉底部的间距即可完全删除最右边的滚动条。
This is the simple way to do a fixed header it gets a little more complex when you want to do a fixed footer as well. This should work for you though.
This one is a little better we just need to get rid of the spacing at the bottom to remove the far right scrollbar completely.