在父div中设置了两个div-左侧的侧边栏和右侧的内容区域。我需要将内容区域(具有固定宽度)的位置设置为始终位于侧边栏右侧的15px (即使浏览器窗口/侧边栏正在伸展)。
设置侧边栏的position: absolute &a% width对侧边栏本身非常有效,但是由于侧边栏的位置是绝对的,所以内容无法识别侧边栏的位置,也不能使用CSS相对于侧边栏进行定位。
下面是我正在努力实现的目标:
发布于 2013-05-16 15:12:13
为什么你要在侧边栏中使用绝对位置?
我只会这样做
<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*/
Link to JS Fiddle to have a look
除非我没听懂你的问题?
https://stackoverflow.com/questions/16581018
复制相似问题