繁体   English   中英

设置div相对于另一个百分比宽度div的位置的位置

[英]Set position of div relative to position of another percentage-width div

我在父div中设置了两个div - 左侧的侧边栏和右侧的内容区域。 我需要将我的内容区域(具有固定宽度)的位置设置为始终为侧边栏右侧的15px(即使浏览器窗口/侧边栏拉伸)。

设置侧边栏的位置:绝对和%宽度对于侧边栏本身非常有效,但由于侧边栏位置是绝对的,因此内容无法识别侧边栏的位置,也无法使用CSS相对于侧边栏定位。

这是我想要实现的目标的图像:

在此输入图像描述

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

我会这样做的

    <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来看看

除非我不理解你的问题?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM