Stop absolutely positioned div from overlapping text

前端 未结 8 2034
旧时难觅i
旧时难觅i 2020-12-24 06:03

Here is a simplification of my layout:

8条回答
  •  暖寄归人
    2020-12-24 06:29

    If you are working with elements of unknown size, and you want to use position: absolute on them or their siblings, you're inevitably going to have to deal with overlap. By setting absolute position you're removing the element from the document flow, but the behaviour you want is that your element should be be pushed around by its siblings so as not to overlap...ie it should flow! You're seeking two totally contradictory things.

    You should rethink your layout.

    Perhaps what you want is that the .btn element should be absolutely positioned with respect to one of its preceding siblings, rather than against their common parent? In that case, you should set position: relative on the element you'd like to position the button against, and then make the button a child of that element. Now you can use absolute positioning and control overlap.

提交回复
热议问题