I'm building a highscores page template, And would like to trim the username (ideally with CSS) if the username and/or score is too long. See this picture :
I can use
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
overflow-y:none;
To trim the username, but how can I trim it relatively to the score length ?
Have you got an idea of how doing this ? Here's a Codepen of my current code : http://codepen.io/anon/pen/yymZGM
Thanks
Just move the score span (which is floated right) before the name
Updated CODEPEN
#highscores {
width: 400px;
padding: 1em;
background-color: yellow;
margin: auto;
font-size: 1.5em;
}
#highscores .round {
font-size: 1.2em;
line-height: 1.2em;
height: 1.2em;
position: relative;
background-color: red;
padding: 0.4em 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
overflow-y: none;
}
#highscores .round .round-index {
padding-right: 2%;
}
#highscores .round .round-author {
font-weight: 700;
width: 60%;
}
#highscores .round .round-score {
width: 28%;
float: right;
text-align: right;
}
<div id="highscores" class="celio-black">
<p id="round-4" class="round">
<span class="round-score">75</span>
<span class="round-index">01</span>
<span class="round-author">grosbouff</span>
</p>
<p id="round-1" class="round">
<span class="round-score">75486987</span>
<span class="round-index">02</span>
<span class="round-author">I have a super long name isn't it ?</span>
</p>
</div>