How to place two divs side by side where LEFT one is sized to fit and other takes up remaining space?

后端 未结 2 1551
死守一世寂寞
死守一世寂寞 2021-02-13 04:44

I\'m trying to place two div\'s beside each other with the following criteria:

  1. Both divs must stay on the same line.
  2. Priority mus
相关标签:
2条回答
  • 2021-02-13 05:28

    I have it with the exception that when there is empty space my right div is eating it (with text right aligned). You don't list that as an ask, so I was unsure if it was just how you drew it? Fiddle here: http://jsfiddle.net/mdares/fSCr6/

    HTML:

    <div class="container">
        <div class="left">Some Text, Repeat, Repeat, Repeat, ,Some Text, and then: </div>
        <div class="right">other Text ttt other Text tttother Text tttother Text ttt</div>
    </div>
    
    <p />
    
    <div class="container">
        <div class="left">Some Text, Repeat, Repeat, Repeat, ,Some Text, Some Text, Repeat, Repeat, Repeat, ,Some Text,</div>
        <div class="right">other Text ttt other Text tttother Text tttother Text ttt</div>
    </div>
    
    <p />
    
    <div class="container">
        <div class="left">Some Text, Repeat, Repeat, Repeat, ,Some Text, </div>
        <div class="right">other Text ttt</div>
    </div>
    

    CSS:

    .container {
        width: 600px;
    }
    .left {
        max-width: 100%;
        background:red;
        white-space:nowrap;
        overflow:hidden;
        text-overflow:ellipsis;
        -ms-text-overflow:ellipsis;
        float: left;
    }
    .right {
        background:yellow;
        white-space:nowrap;
        overflow:hidden;
        text-overflow:ellipsis;
        -ms-text-overflow:ellipsis;
        text-align: right;
    }
    

    And finally:

    enter image description here

    0 讨论(0)
  • 2021-02-13 05:44

    Except the container width That can be defined in % here's a solution. The only crack that worked was putting container backgroud as that of child one.

    or else the last condition is really hard to achieve :) Just being True.

    Here's the fiddle link

    width fiddle

    Here's the css

    .container {
    width: 100%;
    overflow:hidden;
    whitespace:nowrap;
    max-width:100%;
        background-color:red;
    }
    .left {
        width:auto;
        background:red;
        white-space:nowrap;
        overflow:hidden;
        text-overflow:ellipsis;
        -ms-text-overflow:ellipsis;
        float: left;
        position:absolute;
        max-width:inherit;
    }
    .right {
        background:yellow;
        white-space:nowrap;
        overflow:hidden;
        text-overflow:ellipsis;
        -ms-text-overflow:ellipsis;
        text-align: right;
        width:auto;
        float:right;
    }
    

    See to it if it fits . Last condition really tough if some one has another solution to the last image you pasted then please share :)

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