CSS: Make two floating elements overlap

前端 未结 8 1560
臣服心动
臣服心动 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:10

    Make container bigger so both fit. Then use position relative and left: -100px or whatever on the one on the right.

    0 讨论(0)
  • 2021-01-03 20:17

    How about pulling the right div with negative margin. Something like this?

    <div id="container">
        <div id="left">left</div>
        <div id="right">right</div>
    </div>
    
    #container {
        position: relative;
        width: 400px;
        height: 110px;
        background-color: #eee;
    }
    
    #left {
        width: 250px;
        height: 100px;
        border: 1px solid green;
        float: left;
    }
    
    #right {
        position: relative;
        float: right;
        width: 250px;
        height: 100px;
        top: -100px;
        border: 1px solid red;
    }
    
    0 讨论(0)
提交回复
热议问题