如何并排放置两个div,其中LEFT一个适合其他,另一个占用剩余空间?

Phi*_*phy 14 html ellipsis css3

我正在尝试使用以下标准将两个div放在一起:

  1. 两个div必须保持在同一条线上.
  2. 必须优先考虑左div.尽可能多的文本应该显示在左边的div中,直到溢出的情况下使用省略号.
  3. 正确的div文本应该是右对齐的.在溢出的情况下,应使用省略号.
  4. 文本是动态的,因此不能使用百分比或固定宽度.
  5. 只需要在webkit基于浏览器的基础上工作,因此CSS3首选解决方案.

以下是一些示例图像:

输入

<div class='left'>I should always fit. If not, ellipsis should be used.</div><div class='right'>Right align and fit me if space available here.</div>
Run Code Online (Sandbox Code Playgroud)

产量

在此输入图像描述

输入

<div class='left'>I should always fit. If not, ellipsis should be used. And some more text and more, and more text.</div><div class='right'>Right align and fit me if space available here.</div>
Run Code Online (Sandbox Code Playgroud)

产量

在此输入图像描述

输入

<div class='left'>This text is left aligned.</div><div class='right'>This text is right aligned.</div>
Run Code Online (Sandbox Code Playgroud)

产量

在此输入图像描述

Mat*_*hew 9

我有它的例外,当有空的空间时我的右边的div正在吃它(文本右对齐).你没有把它列为一个问题,所以我不确定这是不是你是如何绘制它的?在这里小提琴: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>
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

最后:

在此输入图像描述