Fixed positioned div within a relative parent div

后端 未结 9 1891
春和景丽
春和景丽 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 18:40

    you can fix the wrapper using absolute positioning. and the give inside div a fixed position.

    .wrapper{
     position:absolute;
     left:10%;// or some valve in px
     top:10%; // or some valve in px
     }
    

    and div inside that

    .wrapper .fixed-element{ 
    position:fixed;
    width:100%;
    height:100%;
    margin-left:auto; // to center this div inside at center give auto margin
    margin-right:auto;
    }
    

    try this It might work for you

提交回复
热议问题