在相对父div中固定定位的div [英] Fixed positioned div within a relative parent div

查看:272
本文介绍了在相对父div中固定定位的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在建立一个自适应网站,需要一个固定的菜单,因此,当网站的其余部分滚动时不滚动。问题是,它是一个流体布局,我想要固定位置菜单项相对于包含的父元素,而不是浏览器窗口固定。

I am currently building a responsive website and need a menu to be fixed, thus not scrolling when the rest of the site scrolls. the issue is that it is a fluid layout and i want the "fixed positioned" menu item to be fixed relative to the containing parent element and not to browser window. is there anyway this can be done?

推荐答案

这个问题在谷歌首先出现,虽然一个老的,所以我发布工作

This question came first on Google although an old one so I'm posting the working answer I found, which can be of use to someone else.

这需要3个div,包括固定的div。

This requires 3 divs including the fixed div.

HTML

<div class="wrapper">
    <div class="parent">
        <div class="child"></div>
    </div>
</div>

CSS

.wrapper { position:relative; width:1280px; }
    .parent { position:absolute; }
        .child { position:fixed; width:960px; }

这篇关于在相对父div中固定定位的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆