Fixed positioned div within a relative parent div

后端 未结 9 1888
春和景丽
春和景丽 2020-12-05 17:40

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

9条回答
  •  半阙折子戏
    2020-12-05 18:21

    Gavin,

    The issue you are having is a misunderstanding of positioning. If you want it to be "fixed" relative to the parent, then you really want your #fixed to be position:absolute which will update its position relative to the parent.

    This question fully describes positioning types and how to use them effectively.

    In summary, your CSS should be

    #wrap{ 
        position:relative;
    }
    #fixed{ 
        position:absolute;
        top:30px;
        left:40px;
    }
    

提交回复
热议问题