美文网首页
CSS3 属性text-overflow:ellipsis的使用

CSS3 属性text-overflow:ellipsis的使用

作者: lvyweb | 来源:发表于2017-04-28 14:41 被阅读93次

如果文本多余一行,由于展示空间有限,故而有的时候需要超过一行显示省略号的设置。可以使用text-overflow设置。

语法:text-overflow: clip|ellipsis|string;

  • clip :修剪文本
  • ellipsis :显示省略符号来代表被修剪的文本。
  • string:使用给定的字符串来代表被修剪的文本。

使用注意事项:

  • 要给容器定义宽度
  • 要设置overflow:hidden;
  • 要给相对应的文字设置:white-space:nowrap
  • 还要设置text-overflow:ellipsis多余的部分会以...的方式出现

下面给出一个带hover效果的小demo

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>text-ellipsis的使用</title>
<style> 
div.test{
    width:200px; 
    white-space:nowrap; 
    overflow:hidden; 
    border:1px solid #000000;
}

div.test:hover{
    text-overflow:inherit;
    overflow:visible;
}
</style>
</head>
<body>

<p>鼠标移动到框内,查看效果.</p>

<div class="test" style="text-overflow:ellipsis;">如果超出会出现省略号,因为设置了text-overflow:ellipsis</div>
<br>
<div class="test" style="text-overflow:clip;">设置超出不会出现省略号,会直接截掉,因为设置了text-overflow:clip</div>

</body>
</html>

相关文章

网友评论

      本文标题:CSS3 属性text-overflow:ellipsis的使用

      本文链接:https://www.haomeiwen.com/subject/smzozttx.html