How to place two divs next to each other?

后端 未结 13 1866
孤独总比滥情好
孤独总比滥情好 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%;
    }
    <div id="first">Stack Overflow is for professional and enthusiast programmers, people who write code because they love it.</div>
        <div id="second">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.</div>
    </div>

    or the easy way

    #wrapper {
      display: flex;
      border: 1px solid black;
    }
    #first {
        border: 1px solid red;
    }
    #second {
        border: 1px solid green;
    }
    <div id="wrapper">
        <div id="first">Stack Overflow is for professional and enthusiast programmers, people who write code because they love it.</div>
        <div id="second">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.</div>
    </div>

    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.

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