小编Sta*_*ess的帖子

相对于祖父母,位置元素在绝对父级内

我有子元素需要absolute与祖父母定位.问题是父母也是绝对定位的.

我不能使用JavaScript.我怎样才能用纯CSS实现这个目标?

JSFiddle演示

<div class="col-md-6 gp">
    <div class="col-md-4 p">
        <div class="col-md-2 c"> position me w.r.t to .gp</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)
.gp { height : 200px; position: relative; }

.p {
    height : 100px; width: 250px;
    position :absolute;
    top : 50px; left: 50px;
}

.c { position: absolute; height: 50px; }
Run Code Online (Sandbox Code Playgroud)

html css css-position

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

css ×1

css-position ×1

html ×1