2017-05-10 33 views
-2

如何垂直對齊單條或多條線?如何垂直對齊單條或多條線

我需要省略號,因爲在某些情況下,我只想顯示一行,有時兩行。

這是我到目前爲止的代碼:

html, body, p { 
    margin: 0; 
    padding: 0; 
    font-family: sans-serif; 
} 
.ellipsis { 
    height: 100px; 
    border: 5px solid #AAA; 
} 

.blah { 
    overflow: hidden; 
    height: 1.2em; 
    line-height: 1.2em; 
    display: block; 

} 
.blah:before { 
    content:""; 
    float: left; 
    width: 5px; 
    height: 3.6em; 
} 
.blah > *:first-child { 
    float: right; 
    width: 100%; 
    margin-left: -5px; 
} 

活生生的例子:http://jsfiddle.net/0dqef9da/274/

+0

[上第二行CSS省略號]的可能的複製(HTTP:/ /stackoverflow.com/questions/5269713/css-ellipsis-on-second-line) – Troyer

+0

這不是我的問題......我的問題是如何垂直對齊單行或多行 – bundy

+1

您的問題陳述是不明確的。 「[...]在某些情況下,我只想顯示一行,有時兩行」。在什麼情況下*完全*? –

回答

-2

你應該在你的文本的CSS樣式屬性使用word-break:break-all

-2

垂直居中對齊您使用簡單text-align: center;,如果你想用省略號

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<style> 
 
#div1 { 
 
    white-space: nowrap; 
 
    width: 12em; 
 
    overflow: hidden; 
 
    text-overflow: clip; 
 
    border: 1px solid #000000; 
 
} 
 

 
#div2 { 
 
    white-space: nowrap; 
 
    width: 12em; 
 
    overflow: hidden; 
 
    text-overflow: ellipsis; 
 
    border: 1px solid #000000; 
 
} 
 

 
</style> 
 
</head> 
 
<body> 
 

 
<p>The following two divs contains a long text that will not fit in the box. As you can see, the text is clipped.</p> 
 

 
<p>This div uses "text-overflow:clip":</p> 
 
<div id="div1">This is some long text that will not fit in the box</div> 
 

 
<p>This div uses "text-overflow:ellipsis":</p> 
 
<div id="div2">This is some long text that will not fit in the box</div> 
 

 
</body> 
 
</html>

請按照鏈接: https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_text-overflow

在省略號,你需要還DIV寬度。請檢查上面的代碼

+0

如何顯示兩行?如果我需要 – bundy

+0

你(錯誤地)指出'text-align:center'會垂直對齊,然後從你的解決方案中完全省略它... –

+0

請檢查這個鏈接:http://stackoverflow.com/questions/5269713/ css-ellipsis-on-line-line –