使用text-overflow: ellipsis;文字溢出,代码如下
.content {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
通常情况下使用文字省略需要给一个固定的宽度,文字溢出后省略;当我们存在一种flex自适应布局时,我们无法给定一个固定宽度,内容宽度是根据外部元素宽度自适应,左侧固定,右侧flex: 1来自适应,代码如下
<div class="containter">
<div class="left">left</div>
<div class="right">
<div class="content">
省略文字省略文字省略文字省略文字省略文字省略文字省略文字省略文字省略文字省略文字
</div>
</div>
</div>
.containter {
width: 500;
height: 40px;
display: flex;
align-items: center;
border: 1px solid black;
.left {
width: 100px;
height: 20px;
flex: none;
background-color: blanchedalmond;
}
.right {
flex: 1;