Fixed position but relative to container

后端 未结 25 2123
独厮守ぢ
独厮守ぢ 2020-11-21 23:52

I am trying to fix a div so it always sticks to the top of the screen, using:

position: fixed;
top: 0px;
right: 0px;

However,

25条回答
  •  暖寄归人
    2020-11-22 00:39

    Yes it is possible as long as you don't set the position (top or left, etc.) of your fixed element (you can still use margin to set a relative position, though). Simon Bos posted about this a while ago.

    However don't expect fixed element to scroll with non-fixed relatives.

    See a demo here.

提交回复
热议问题