dreamweaver、记事本、或其他可以写代码的工具
一、利用{overflow: hidden; text-overflow:ellipsis; white-space: nowrap;}**三个属性必须一起使用,其中ellipsis是省略号效果,这种方式只适合单行文本。效果如下图:
二、利用WebKit的CSS扩展属性,该方法适用于WebKit浏览器及移动端;{display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;}1、-webkit-line-clamp限制在一个块元素中文本显示的行数。它需要组合其他的WebKit属性。常见结合属性:2、display: -webkit-box; 必须结合的属性 ,将对象作为弹性伸缩盒子模型显示 。3、-webkit-box-orient 必须结合的属性 ,设置或检索伸缩盒对象的子元素的排列方式 。效果如下图:
三、我最喜欢的方法,.nr .text{position: relative; line-height: 20px; max-height:120px;overflow: hidden;}.text:after{content: '....'; color:#000; position: absolute; bottom: 0; right: 0; padding-left:60px;background: -webkit-linear-gradient(left, transparent, #C4E2D870%);background: -o-linear-gradient(right, transparent, #C4E2D8 70%);background: -moz-linear-gradient(right, transparent, #C4E2D8 70%);background: linear-gradient(to right, transparent,#C4E2D8 70%);}**注意1、将height设置为line-height的整数倍,防止超出的文字露出。2、给 .text:after 添加渐变背景可避免文字只显示一半。3、4个background是一个意思,一个效果,只是为了兼容不同浏览器;常用浏览器使用最后一个background就可以了。