CSS position element “fixed” inside scrolling container

后端 未结 5 2149
抹茶落季
抹茶落季 2020-12-05 22:49

i wonder if anyone has found a solution for this?

i am looking for a solution to attach an element to the top of a scrolling container

HTML:

         


        
5条回答
  •  囚心锁ツ
    2020-12-05 23:45

    I think your solution pass with position:sticky. Seems it's like position:fixed but respects the relative position to his parent.

    Unfortunately this is an experimental feature, and is only supported in Chromium. You can see more details in this test page.

    The pure css solution that comes into my mind is with a little change of the markup. You can set a container only for the "elements" as this:

    ......
    .....

    And give the overflow to this inner container. Now, your header sticks at top.

    Here's a working demo.

提交回复
热议问题