How to place two divs next to each other?

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

Consider the following code:

13条回答
  •  独厮守ぢ
    2020-11-22 06:31

    It is very easy - you could do it the hard way

    .clearfix:after {
       content: " "; 
       visibility: hidden;
       display: block;
       height: 0;
       clear: both;
    }
    
    #first, #second{
      box-sizing: border-box;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
    }
    
    #wrapper {
        width: 500px;
        border: 1px solid black;
    }
    #first {
        border: 1px solid red;
        float:left;
        width:50%;
    }
    #second {
        border: 1px solid green;
        float:left;
        width:50%;
    }
    Stack Overflow is for professional and enthusiast programmers, people who write code because they love it.
    When you post a new question, other users will almost immediately see it and try to provide good answers. This often happens in a matter of minutes, so be sure to check back frequently when your question is still new for the best response.

    or the easy way

    #wrapper {
      display: flex;
      border: 1px solid black;
    }
    #first {
        border: 1px solid red;
    }
    #second {
        border: 1px solid green;
    }
    Stack Overflow is for professional and enthusiast programmers, people who write code because they love it.
    When you post a new question, other users will almost immediately see it and try to provide good answers. This often happens in a matter of minutes, so be sure to check back frequently when your question is still new for the best response.

    There's also like a million other ways.
    But I'd just with the easy way. I would also like to tell you that a lot of the answers here are incorrect But both the ways that I have shown at least work in HTML 5.

提交回复
热议问题