CSS: Make two floating elements overlap

前端 未结 8 1749
臣服心动
臣服心动 2021-01-03 19:28

I have two divs within a container. One floats left and one floats right. Both are about 60% as wide as the container and are designed such that they overlap in the middle (

8条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 19:51

    You could create the divs with absolute position and add a positive z-index to the one you want to be in front.

    left
    #container { width: 400px; background-color: #eee; position: relative; } #left { width: 250px; border: 1px solid #ccc; display: block; position: absolute; top: 0px; left: 0px; } #right { width: 250px; border: 1px solid #ccc; display: inline; position: absolute; top: 0px; right: 0px; z-index: 1; }

提交回复
热议问题