[英]How to trim a text?
设置样式text-overflow, white-space, overflow
属性:
<div style="background: green;height: 27px;overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100px;"> This is text to be written here </div>
使用text-overflow: ellipsis;
带有white-space: nowrap; overflow: hidden;
属性white-space: nowrap; overflow: hidden;
white-space: nowrap; overflow: hidden;
。
所以,你的代码看起来像这样
<div style="background:green; width:100px; height:27px;text-overflow: ellipsis;white-space: nowrap; overflow: hidden;">
This is text to be written here
</div>
这是对正在发生的事情的一个很好的解释。
设置以下样式属性:
text-overflow:ellipsis
white-space:nowrap
overflow:hidden
<div style="background:green; width:100px; height:27px; text-overflow:ellipsis; white-space:nowrap; overflow:hidden;"> This is text to be written here </div>
将此css添加到您的代码中:
div{ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
<div style="background:green; width:100px; height:27px;"> This is text to be written here </div>
这是使用css或jquery修剪文本的代码
jQuery的
<div id="text">
This is text to be written here
</div>
<script type="text/javascript">
$(document).ready(function(){
var text =$('#text').html();
if(text.length>20){
$('#text').html(text.substr(0,20)+'...') ;
}
});
CSS
<div id="css">
This is text to be written here
</div>
#css {
text-overflow: ellipsis ;
background:green;
width:100px;
height:27px;
display:inline-block;
overflow: hidden;
white-space:nowrap;
}
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.