I have a horizontal list with ...-truncated titles which I want to be centered.
The centering works in Safari (top), but not in Chrome (bottom):
ul {
width: 100px;
display: flex;
justify-content: center;
align-items: center;
}
li {
width: calc(100% / 2);
display: block;
}
div {
text-align: center;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid red;
}
<ul>
<li>
<div>
IIIIMMM
</div>
</li>
<li>
<div>
MMMM
</div>
</li>
</ul>
Problem can be simplified as
div {
text-align: center;
width: 7em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
border: 1px solid red;
}
<div>a⸻b…</div>
<div>a⸻b⸻c</div>
<p>Both <code>div</code>s should be identical.</p>
Rendered outcome in Chrome and Firefox: