CSS 布局 - 重叠的 div

发布于 2024-12-14 15:45:22 字数 1307 浏览 3 评论 0原文

我有一个非常顽固的布局,我无法解决..

- Left column - Fixed,Static (always in view)
- Right column - Fluid/liquid/scrollable
--- Header - fixed 
--- left/main fluid/liquid
--- Right/sidebar - fixed width
--- footer

(如果上面不清楚 - 标题,左/主,右/侧边栏,页脚位于右列内)

现在,这种布局有点工作,

<div id="left-col">left col</div>

<div id="container">

    <div id="header">header</div>
    <div id="main">
        <div id="sidebar">sidebar</div>
        main
    </div>
    <div id="footer">footer</div>
</div>

#left-col {
    width: 50px;
    position: fixed;
    background: yellow;
    left: 0;
    top: 0;
}
#container {
    margin-left: 50px;
    background: black;
}
#header {
    background: green;
}
#main {
    background: blue;
    position: relative;
}
#sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 50px;
    background: pink;
}
#footer {
    background: red;
}

但仍然我有一个恼人的问题—— 当主要内容不够长时 - 侧边栏和页脚重叠.. 这是因为侧边栏是:绝对定位 - 但话又说回来,如果我将其设置为相对位置,并且正在重新调整页面大小,则侧边栏将位于主栏下方...(没有足够的空间容纳流体...) 所以,我的问题是, 有人知道如何将页脚保持在侧边栏下方吗? (jQuery 粘性技巧不起作用,CSS 技巧在这里非常棘手..) 或任何其他IDE来实现这种布局?

JSFIDDLE: http://jsfiddle.net/VNU6Z/

I have a really stuburn layout, that I just can not resolve ..

- Left column - Fixed,Static (always in view)
- Right column - Fluid/liquid/scrollable
--- Header - fixed 
--- left/main fluid/liquid
--- Right/sidebar - fixed width
--- footer

(if the above is not clear - header,left/main,right/sidebar,footer are INSIDE the right column)

now, this layout sort of working ,

<div id="left-col">left col</div>

<div id="container">

    <div id="header">header</div>
    <div id="main">
        <div id="sidebar">sidebar</div>
        main
    </div>
    <div id="footer">footer</div>
</div>

#left-col {
    width: 50px;
    position: fixed;
    background: yellow;
    left: 0;
    top: 0;
}
#container {
    margin-left: 50px;
    background: black;
}
#header {
    background: green;
}
#main {
    background: blue;
    position: relative;
}
#sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 50px;
    background: pink;
}
#footer {
    background: red;
}

but still I have one annoying problem -
when the main content is not long enough - the sidebar and the footer are overlapping ..
That is because the sidebar is : absolute positioned - but then again, If i make it relative, and the page is being re-sized, the sidebar goes UNDER the main ... (not enough space for fluid ...)
so , my question is this ,
Anyone has an Idea how to keep the footer UNDER the sidebar ? (jQuery sticky tricks not working, and CSS tricks are quite tricky here..)
or any other ides to achieve this layout ?

JSFIDDLE: http://jsfiddle.net/VNU6Z/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初心 2024-12-21 15:45:25

您可以使用 float:right 代替绝对位置

sample

You can use float:right instead of position absolute

sample

忘你却要生生世世 2024-12-21 15:45:25

金是对的。使 div id="sidebar" float:right 并使 div id="main" overflow:hidden

然后 div id="main" 将调整浮动元素的大小,就像它具有 float:left 一样

Kim is right. Make div id="sidebar" float:right, and make div id="main" overflow:hidden

div id="main" will then resize to your floated elements as though it had float:left

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文