Display Two
s Side-by-Side

前端 未结 3 892
忘掉有多难
忘掉有多难 2020-12-08 06:50

My goal is to display two

s side-by-side with the content from both
s aligned at the top. I do not want long text in the seco
相关标签:
3条回答
  • 2020-12-08 07:34

    Try to Use Flex as that is the new standard of html5.

    http://jsfiddle.net/maxspan/1b431hxm/

    <div id="row1">
        <div id="column1">I am column one</div>
        <div id="column2">I am column two</div>
    </div>
    
    #row1{
        display:flex;
        flex-direction:row;
    justify-content: space-around;
    }
    
    #column1{
        display:flex;
        flex-direction:column;
    
    }
    
    
    #column2{
        display:flex;
        flex-direction:column;
    }
    
    0 讨论(0)
  • 2020-12-08 07:34

    Try this : (http://jsfiddle.net/TpqVx/)

    .left-div {
        float: left;
        width: 100px;
        /*height: 20px;*/
        margin-right: 8px;
        background-color: linen;
    }
    .right-div {
    
        margin-left: 108px;
        background-color: lime;
    }​​
    

    <div class="left-div">
        &nbsp;
    </div>
    <div class="right-div">
        My requirements are <b>[A]</b> Content in the two divs should line up at the top, <b>[B]</b> Long text in right-div should not wrap underneath left-div, and <b>[C]</b> I do not want to specify a width of right-div. I don't want to set the width of right-div because this markup needs to work within different widths.
    </div>
    <div style='clear:both;'>&nbsp;</div>
    

    Hints :

    • Just use float:left in your left-most div only.
    • No real reason to use height, but anyway...
    • Good practice to use <div 'clear:both'>&nbsp;</div> after your last div.
    0 讨论(0)
  • 2020-12-08 07:37

    I removed the float from the second div to make it work.

    http://jsfiddle.net/rhEyM/2/

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