2017-04-03 81 views
0

我想要的東西其實是有1個或最多2行文字,如果用省略號再被截斷。它沒有顯示,由於某種原因時,它的內部.cell股利超過2行文字,然後將文本框是跳躍起來。爲什麼包裝文本會導致div框向上移動?

body { 
 
    background-color: transparent; 
 
    overflow-y: hidden; 
 
    margin: 0; 
 
} 
 

 
div { 
 
    font-size: 20px; 
 
    text-overflow: ellipsis; 
 
} 
 

 
.container { 
 
    white-space: nowrap; 
 
    overflow-x: hidden; 
 
    overflow-y: hidden; 
 
    font-size: 0; 
 
    height: 100vh; 
 
} 
 

 
.row { 
 
    white-space: nowrap; 
 
    overflow-x: hidden; 
 
    font-size: 0; 
 
    background-color: cyan; 
 
} 
 

 
.cell { 
 
    display: inline-block; 
 
    white-space: normal; 
 
    width: 200px; 
 
    height: 200px; 
 
    background-color: lime; 
 
    margin: 5px; 
 
    padding: 0px; 
 
    z-index: -1; 
 
} 
 

 
.cellDummy { 
 
    display: inline-block; 
 
    white-space: normal; 
 
    height: 200px; 
 
    background-color: blue; 
 
    margin: 0px; 
 
    padding: 0px; 
 
    z-index: -1; 
 
}
<div class="container"> 
 
    <div class="row" id="row0"> 
 
    <div class="cellDummy" style="width: 740.5px;">boo</div> 
 
    <div class="cell">1 ahsdjkha sdjha kshd kajhs dajhsdk</div> 
 
    <div class="cell">2</div> 
 
    <div class="cell">3</div> 
 
    </div> 
 
</div>

enter image description here

所以,問題是如何排隊.cell盒甚至有2行文字?如果文本不適合2行(或者框的高度的10%),如何進行省略號?

更新 現在更改垂直對齊.cellDummy框跳轉。

enter image description here

回答

1

因爲行內元素的默認垂直對齊方式爲baseline,這是你所看到的。嘗試將其更改爲top

body { 
 
    background-color: transparent; 
 
    overflow-y: hidden; 
 
    margin: 0; 
 
} 
 

 
div { 
 
    font-size: 20px; 
 
    text-overflow: ellipsis; 
 
} 
 

 
.container { 
 
    white-space: nowrap; 
 
    overflow-x: hidden; 
 
    overflow-y: hidden; 
 
    font-size: 0; 
 
    height: 100vh; 
 
} 
 

 
.row { 
 
    white-space: nowrap; 
 
    overflow-x: hidden; 
 
    font-size: 0; 
 
    background-color: cyan; 
 
} 
 

 
.cell { 
 
    display: inline-block; 
 
    white-space: normal; 
 
    width: 200px; 
 
    height: 200px; 
 
    background-color: lime; 
 
    margin: 5px; 
 
    padding: 0px; 
 
    z-index: -1; 
 
    vertical-align:top; 
 
} 
 

 
.cellDummy { 
 
    display: inline-block; 
 
    white-space: normal; 
 
    height: 200px; 
 
    background-color: blue; 
 
    margin: 0px; 
 
    padding: 0px; 
 
    z-index: -1; 
 
}
<div class="container"> 
 
    <div class="row" id="row0"> 
 
    <div class="cellDummy" style="width: 740.5px;">boo</div> 
 
    <div class="cell">1 ahsdjkha sdjha kshd kajhs dajhsdk</div> 
 
    <div class="cell">2</div> 
 
    <div class="cell">3</div> 
 
    </div> 
 
</div>

要設置你需要定義text-overflowoverflow性能省略號。

+0

現在我的'.cellDummy'跳起來...... – Pablo

+0

對於文本省略號我想我需要內股利或跨度,在'.cell'佔據固定的高度? – Pablo

+0

您的'.cell' div上有一個保證金,您的.'cellDummy'沒有。是的,你需要定義一個高度省略號在踢 – j08691