用css截取字串長度的方法

來源:互聯網
上載者:User

有時我們在做頁面展示的時候,會遇到文章標題字元過多的問題,需要截取一定長度並後面用省略符號代替。這個可以用css來實現。不過在Firefox瀏覽器上不顯示省略符號,用時要注意相容性。

 

<style type="text/css">
.cutLen{...}{
    width:200px;
    overflow:hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
}
</style>
<div class="cutLen">用CSS截取字串,在Firefox瀏覽器看看</div>
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.