Fixed position but relative to container

后端 未结 25 2082
独厮守ぢ
独厮守ぢ 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:40

    position: sticky that is a new way to position elements that is conceptually similar to position: fixed. The difference is that an element with position: sticky behaves like position: relative within its parent, until a given offset threshold is met in the viewport.

    In Chrome 56 (currently beta as of December 2016, stable in Jan 2017) position: sticky is now back.

    https://developers.google.com/web/updates/2016/12/position-sticky

    More details are in Stick your landings! position: sticky lands in WebKit.

提交回复
热议问题