gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 12:27:12 25 4
gpt4 key购买 nike

我正在尝试按照以下标准将两个 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>

输出

enter image description here

输入

<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>

输出

enter image description here

输入

<div class='left'>This text is left aligned.</div><div class='right'>This text is right aligned.</div>

输出

enter image description here

最佳答案

我有它,但当有空白空间时我的右 div 正在吃它(文本右对齐)。你没有把它列为一个问题,所以我不确定你是不是这样画的?在这里 fiddle :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;
}

最后:

enter image description here

关于css - 如何并排放置两个 div,其中 LEFT 一个大小适合,另一个占用剩余空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18824050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com