CSS: Make two floating elements overlap

前端 未结 8 1581
臣服心动
臣服心动 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 20:03

    Use a negative margin-right on the left box so that the right box is allowed to overlap:

    #left {
        width: 250px;
        border: 1px solid #ccc;
        display: inline;
        float: left;
        margin-right:-104px;
    }
    

    The 104 pixels is the overlap amount plus 4px for borders.

    Here's a jsfiddle.

提交回复
热议问题