How to remove an element from the flow?

前端 未结 9 1696
Happy的楠姐
Happy的楠姐 2020-12-24 00:11

I know position: absolute will pop an element from the flow and it stops interacting with its neighbors.

What other ways are there to achieve this?

9条回答
  •  無奈伤痛
    2020-12-24 00:45

    position: fixed; will also "pop" an element out of the flow, as you say. :)

    position: absolute must be accompanied by a position. e.g. top: 1rem; left: 1rem

    position: fixed however, will place the element where it would normally appear according to the document flow, but prevent it from moving after that. It also effectively set's the height to 0px (with regards to the dom) so that the next element shifts up over it.

    This can be pretty cool, because you can set position: fixed; z-index: 1 (or whatever z-index you need) so that it "pops" over the next element.

    This is especially useful for fixed position headers that stay at the top when you scroll, for example.

提交回复
热议问题