0

I two divs set within a parent div - a sidebar on the left & a content area to the right of that. I need to set the position of my content area (which has a fixed width) to always be 15px to the right of the sidebar (even as the browser window / sidebar stretches).

Setting the sidebar with position: absolute & a % width worked perfectly for the sidebar itself, but as the sidebar position is then absolute, the content doesn't recognise where the sidebar is & can't be positioned relative to it with CSS.

Here is an image of what I am trying to achieve:

enter image description here

4

1 回答 1

2

为什么你在侧边栏使用绝对位置?

我会这样做

    <div class="container">
        <div class="sidebar">
            <p>This is your sidebar</p>
        </div>
        <div class="content">
            <p>This is your content</p>
        </div>
    </div>


.container {width:100%; height: 1000px; background:blue;} /*didn't supply a width*/
.sidebar {width:25%; float:left; min-height:200px; background:lightblue; margin-right:15px;} /*you said sidebar has a % width*/
.content {width:250px; height:200px; background:red; float:left;} /*you said content had fixed width*/

链接到 JS Fiddle 看看

除非我不理解你的问题?

于 2013-05-16T07:12:13.197 回答