Vertical border between floating DIVs using CSS

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

I have the following HTML structure

Some text goes here
Dif
相关标签:
4条回答
  • 2021-01-18 06:08

    The simple one:

    elements {
      border-left: black solid 1px;
    }
    
    elements:nth-child(1) {
      border-left: none;
    }
    
    0 讨论(0)
  • 2021-01-18 06:09

    try to use

    border-left:1px solid #color;
    margin-left:2px;
    

    and

    border-right:1px solid #color;
    margin-right:2px;
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-18 06:29

    You could also give border-right: 1px solid #000; only to your first div if this div is longer than second div and if second div is longer you could assign border-left: 1px solid #000; only to your second div.

    0 讨论(0)
提交回复
热议问题