2017-08-06 48 views
1

我無法按照需要的方式運行text-overflow: ellipsisoverflow: hidden帶有溢出和省略號不起作用的嵌套柔性容器

基本上,我需要得到具有item1類和文本左格「請截斷我」縮小爲容器的寬度減小,這樣既item1item2都在同一行。

無論我嘗試什麼,最終都會出現行溢出並且永不縮水。

從這裏嘗試了各種解決方案,但沒有設法得到我需要的任何工作。

.mainwrapper { 
 
    display: flex; 
 
    justify-content: center; 
 
    width: 100%; 
 
    max-width: 100%; 
 
    height: 100%; 
 
    max-height: 100%; 
 
} 
 

 
.content { 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: center; 
 
    margin-top: 20px; 
 
    margin-bottom: 20px; 
 
    max-width: 800px; 
 
    width: 100%; 
 
    height: 400px; 
 
    background-color: red; 
 
} 
 

 
.top-container { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
    width: 80%; 
 
    height: 80%; 
 
    background-color: cyan; 
 
} 
 

 
.title { 
 
    background-color: white; 
 
} 
 

 
.table-container { 
 
    display: table; 
 
} 
 

 
.skills-container { 
 
    width: 100%; 
 
    display: block; 
 
    background-color: green; 
 
} 
 

 
.skill-row { 
 
    width: 100%; 
 
    display: flex; 
 
    justify-content: start; 
 
    background-color: blue; 
 
} 
 

 
.item1 { 
 
    display: flex; 
 
    flex-wrap: nowrap; 
 
} 
 

 
.item2 { 
 
    flex-shrink: 0; 
 
    display: flex; 
 
    flex-wrap: nowrap; 
 
} 
 

 
.item-content { 
 
    display: flex; 
 
} 
 

 
.item-details { 
 
    display: flex; 
 
} 
 

 
.text1 { 
 
    display: inline-block; 
 
    white-space: nowrap; 
 
    background-color: yellow; 
 
} 
 

 
.small-button { 
 
    display: flex; 
 
    height: 50px; 
 
    width: 50px; 
 
    background-color: green; 
 
} 
 

 
.overflow-toverflow { 
 
    overflow: hidden; 
 
    text-overflow: ellipsis; 
 
} 
 

 
.flex-w { 
 
    flex-wrap: wrap; 
 
} 
 

 
.flex-nw { 
 
    flex-wrap: nowrap; 
 
} 
 

 
.flex-min { 
 
    flex: 1 1 auto; 
 
    min-width: 0; 
 
} 
 

 
.flex-sh-0 { 
 
    flex-shrink: 0; 
 
} 
 

 
.min0 { 
 
    min-width: 0; 
 
}
<div class="mainwrapper"> 
 
    <div class="content flex-min"> 
 
    <div class="top-container flex-min"> 
 
     <div class="title">Your skills</div> 
 
     <div class="table-container"> 
 
     <div class="skills-container"> 
 
      <div class="skill-row flex-nw flex-min"> 
 
      <div class="item1 flex-min"> 
 
       <div class="item-content"> 
 
       <div class="small-button"></div> 
 
       <div class="text1 overflow-toverflow">Please truncate me! Please truncate me!Please truncate me!Please truncate me!Please truncate me!Please truncate me</div> 
 
       </div> 
 
      </div> 
 
      <div class="item2 flex-sh-0"> 
 
       <div class="small-button"></div> 
 
       <div class="text1">Relevance: None Whatsoever None</div> 
 
      </div> 
 
      </div> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

codepen: https://codepen.io/Tiartyos/pen/Ljxyqr

回答

1

初始設置在柔性的項目是min-width: auto。這意味着,默認情況下,項目不能縮小到其內容的大小以下。這可以防止省略號渲染,因爲該項目只是簡單地擴展以容納所有內容。

您的大多數彈性物品都有必要的min-width: 0覆蓋應用。但不是全部。

此外,flex和表格屬性在一起播放不好。混合它們可以打破柔性佈局,這似乎是發生在你的情況。

通過以下調整,您的佈局似乎工作。

​​

revised codepen

更多信息:(該職位將是該鏈接的副本,如果不是爲display: table物)

+1

工程就像一個魅力,謝謝你ou這麼多。 – Tiartyos