How to place two divs next to each other?

后端 未结 13 2055
孤独总比滥情好
孤独总比滥情好 2020-11-22 05:44

Consider the following code:

13条回答
  •  余生分开走
    2020-11-22 06:30

    Having two divs,

    The two divs are
    next to each other.

    you could also use the display property:

    #div1 {
        display: inline-block;
    }
    
    #div2 {
        display: inline-block;
    }
    

    jsFiddle example here.

    If div1 exceeds a certain height, div2 will be placed next to div1 at the bottom. To solve this, use vertical-align:top; on div2.

    jsFiddle example here.

提交回复
热议问题