Vertical border between floating DIVs using CSS

前端 未结 4 600
别那么骄傲
别那么骄傲 2021-01-18 05:52

I have the following HTML structure

Some text goes here
Dif
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 06:26

    I tried border on both divs, (right border on child-1 and left border on div-2, but this is not a good idea, because the line will appear thick where the two divs touch each other and then thin for the extended part.

    That's a good way to go, actually. The final step, though, is to give the right div a negative left margin of 1px (assuming the border is 1px wide), so that the two borders overlap.

    #child-1 {
        width: 500px;
        float: left;
        border-right: 1px solid gray;
    }
    
    #child-2 {
        width: 200px;
        float: left;
        border-left: 1px solid gray;
        margin-left: -1px;
    }
    

    Another option is to use display: table on the parent and then display: table-cell on the columns, and then have a single border line between them.

提交回复
热议问题