2017-02-08 122 views
0

我正在使用多行截断sass mixin。它不会在Chrome中显示“...”。在调试时,我得到了-webkit-box-orient:vertical;没有得到应用。多行截断在Chrome中不显示'...'

下面是代码:

overflow: hidden; 
    max-height: $font-size*$line-height*$lines-to-show; /* Fallback for non-webkit */ 

    display: -webkit-box; 
    -webkit-line-clamp: $lines-to-show; 
    -webkit-box-orient: vertical; 

    // Solution for Opera 
    text-overflow: -o-ellipsis-lastline; 

    font-size: $font-size; 
    line-height: $line-height; 
    text-overflow: ellipsis; 

预先感谢帮助

回答

0

你可以找到在这个帖子的解决方案:

http://hackingui.com/front-end/a-pure-css-solution-for-multiline-text-truncation/

@mixin multiLineEllipsis($lineHeight: 1.2em, $lineCount: 1, $bgColor: white){ 
    overflow: hidden; 
    position: relative; 
    line-height: $lineHeight; 
    max-height: $lineHeight * $lineCount; 
    text-align: justify; 
    margin-right: -1em; 
    padding-right: 1em; 
    &:before { 
    content: '...'; 
    position: absolute; 
    right: 0; 
    bottom: 0; 
    } 
    &:after { 
    content: ''; 
    position: absolute; 
    right: 0; 
    width: 1em; 
    height: 1em; 
    margin-top: 0.2em; 
    background: $bgColor; 
    } 
} 

有一个样本在codepen中你可以看到结果:

http://codepen.io/natonischuk/pen/QbGWBa

+0

这工作正常。但如果我们不想证明文字合理,它会创建一个空白空间。有没有什么方法'...'仍然坚持第三行出现的最后一个单词(linecount-假设它是3) – mahil

+0

我认为您需要做一些javascripting来检测块中最新的可见单词。我不认为这是可能的与CSS现在。 –