【发布时间】:2018-09-23 09:45:09
【问题描述】:
我需要三个元素。两侧有两个元素,中间有一个文本元素。中间的文本需要左对齐(浮动)到第一个元素。
当页面缩小时,我需要用省略号截断文本。但是在指定溢出样式后,当页面缩小到小于三个组合的宽度时,它们开始移动到新位置并移出父容器。
如果宽度不能容纳所有元素,## This is sample text! ## 将变成## This is samp... ##(其中## 是侧元素)。
.container {
height: 30px;
background-color: #ff0000;
}
.container > .container-first {
display: inline-block;
background-color: #0000ff;
width: 20px;
height: 30px;
float: left;
}
.container > .container-second {
display: inline-block;
line-height: 30px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
float: left;
}
.container > .container-third {
display: inline-block;
background-color: #00ff00;
width: 20px;
height: 30px;
float: right;
}
<div class="container">
<div class="container-first"></div>
<div class="container-second">This one has sample text!</div>
<div class="container-third"></div>
</div>
请注意,this answer 没有帮助,因为它只是将每个孩子移动到自己的行。
【问题讨论】: