单行文本省略适用于文本超出内容显示区,则在末尾显示省略号css
普通文本超出显示省略号,示例:git
.p{ height: 30px line-height: 30px; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space:nowrap; }
首先应设置表格属性table-layout
为fixed
;而后再为单元格设置省略,示例:github
table{ table-layout: fixed; } table tr{ height: 30px; line-height: 30px; font-size: 16px; } table tr th,table tr td{ padding: 0 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
多行文本省略适用于文本超出内容显示区高度,则在最后一行的末尾显示省略号this
经过使用伪元素添加content为...的方式显示,此种方法须要引入半透明图片做为伪元素背景,示例:url
.p{ height: 66px; line-height: 22px; position: relative; overflow: hidden; } .p::after{ content: "..."; position: absolute; bottom: 0; right: 0; padding: 0 15px 0px 10px; background: url(../images/modifyInfo/opacity.png) no-repeat right center; } .p:after{ content: "..."; position: absolute; bottom: 0; right: 0; padding: 0 15px 0px 10px; background: url(../images/modifyInfo/opacity.png) no-repeat right center; }
经过引入溢出省略插件dotdotdot.js实现多行省略spa
下载地址: https://github.com/FrDH/jQuery.dotdotdot插件
引入dotdotdot.js,为要省略的内容施加方法便可,示例:code
$('.p').dotdotdot();
切换内容显示/隐藏图片
$(function(){ //动态展开 var unReadNum = 0; $('.right_newestState_con i').each(function(){ if($(this).hasClass('curr')){ unReadNum++; } $('.right_unreadInfo_p2 i').text(unReadNum); }); $('.right_newestState_con em').each(function(){ this.flag = true; var $this = $(this).parent().next(); function createDots() { $this.dotdotdot(); } function destroyDots() { $this.trigger('destroy'); } createDots(); $(this).on('click',function() { if($(this)[0].flag){ unReadNum--; $(this)[0].flag = false; $(this).siblings('i').removeClass('curr'); $('.right_unreadInfo_p2 i').text(unReadNum); if(unReadNum==0){ $('.body_right_unreadInfo span').remove(); } } $this.toggleClass('opend'); if ($this.hasClass('opend')) { $(this).text('[点击收起]'); destroyDots(); } else { $(this).text('[点击展开]'); createDots(); } }); }) })
其余使用方法参考官方demoip