Решение состоит в том, чтобы добавить width: 0;min-width: 0;
к левому тексту, чтобы сделать левую часть без размера, поэтому текст будет переполнен.Тогда из-за white-space:nowrap
вы не увидите никаких визуальных изменений, но правильный текст сможет покрыть его.
html,
body {
margin: 0;
padding: 0;
}
.container--text {
display: flex;
flex-flow: row nowrap;
padding: 10px 0;
animation: change 2s infinite linear alternate;
}
.left {
white-space: nowrap;
width: 0;
min-width: 0;
color: #000000;
font-weight: bold;
}
.right {
white-space: nowrap;
margin-left: auto;
margin-right: 20px;
background-color: #BCAAA4;
color: #616161;
}
@keyframes change {
from{width:500px;}
to{width:230px;}
}
<div class="container--text">
<div class="left">Leeeeeeeeeeeft Text</div>
<div class="right">Rigggggggggggggggght Text</div>
</div>
Или вы можете опустить width:0
и использовать overflow:hidden
, чтобы скрыть текст, когда его контейнер сжимается:
html,
body {
margin: 0;
padding: 0;
}
.container--text {
display: flex;
flex-flow: row nowrap;
padding: 10px 0;
animation: change 2s infinite linear alternate;
}
.left {
white-space: nowrap;
overflow:hidden;
text-overflow:ellipsis;
min-width: 0;
color: #000000;
font-weight: bold;
}
.right {
white-space: nowrap;
margin-left: auto;
margin-right: 20px;
background-color: #BCAAA4;
color: #616161;
}
@keyframes change {
from { width: 500px;}
to { width: 230px; }
}
<div class="container--text">
<div class="left">Leeeeeeeeeeeft Text</div>
<div class="right">Rigggggggggggggggght Text</div>
</div>