高分模板中的 Trim 文本(带有 CSS?)

Trim text (with CSS?) in highscores template

我正在构建高分页面模板, 并且想trim用户名(最好用CSS)如果用户名and/or分值太长。 看这张图:

我可以用

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
overflow-y:none;

给trim用户名,但是我怎么能trim它相对于分数长度呢?

你知道怎么做吗? 这是我当前代码的 Codepen:http://codepen.io/anon/pen/yymZGM

谢谢

只需将分数跨度(向右浮动)移到名称前

已更新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>

这样试试:Demo

.round {
    font-size: 1.2em;
    line-height: 1.2em;
    height:1.2em;
    position: relative;
    padding: 0.4em 0;
    overflow-y:none;
}
.round-index {
    padding-right: 2%;   
}
.round-author {
    font-weight: 700;
    width: 60%;
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background-color:red;  
    display:inline-block;
}
.round-score {
    width: 28%;
    float: right;
    text-align: right;    
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background-color:green;  
    display:inline-block;
}

语义上,你需要一个<table>,这样更简单:

HTML

<table id="highscores" class="celio-black">
  <tr id="round-4" class="round">
    <td class="round-index">01</td>
    <td class="round-author">grosbouff</td>
    <td class="round-score">75</td>
  </tr>                            
  <tr id="round-1" class="round">
    <td class="round-index">02</td>
    <td class="round-author">I have a super long name isn't it ?</td>
    <td class="round-score">75486987</td>
  </tr>                                              
</table>

SCSS

#highscores {
    width: 400px;
    padding: 1em;
    background-color: yellow;
    margin: auto;
    font-size: 1.5em;
    table-layout: fixed;
    border-collapse: collapse;
    .round {
        font-size: 1.2em;
        line-height: 1.2em;
        height: 1.2em;
        position: relative;
        background-color: red;
        padding: 0.4em 0;
        .round-index {
            padding-right: 2%;
        }
        .round-author {
            font-weight: 700;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            overflow-y: none;

        }
        .round-score {
        }
    }
}