CSS3 text-overflow 属性 | CSS3教程:CSS3 文本效果

返回到:CSS3 文本效果 | CSS3教程

属性定义及使用说明

text-overflow 属性指定当文本溢出包含它的元素时,应该如何显示。可以设置溢出后,文本被剪切、显示省略号 (…) 或显示自定义字符串(不是所有浏览器都支持)。

text-overflow 需要配合以下两个属性使用:

  • white-space: nowrap;
  • overflow: hidden;
默认值:auto
继承:no
动画:支持。 
Version:3
JavaScript 语法:object.style.textOverflow=”ellipsis” 

语法

text-overflow: clip|ellipsis|string|initial|inherit;
描述
clip剪切文本。
ellipsis显示省略符号  来代表被修剪的文本。
string使用给定的字符串来代表被修剪的文本。
initial设置为属性默认值。
inherit从父元素继承该属性值。

浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

属性谷歌IE火狐苹果opera
text-overflow4.06.07.03.111.0
9.0 -o-

实例

使用text-overflow属性:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Web176教程网(web176.com)</title>
<style> 
div.test
{
	white-space:nowrap; 
	width:12em; 
	overflow:hidden; 
	border:1px solid #000000;
}
</style>
</head>
<body>

<p>以下 div 容器内的文本无法完全显示,可以看到它被裁剪了。</p>
<p>div 使用 &quot;text-overflow:ellipsis&quot;:</p>

<div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div>
<p>div 使用 &quot;text-overflow:clip&quot;:</p>
<div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div>
<p>div 使用自定义字符串 &quot;text-overflow: &gt;&gt;&quot;(只在 Firefox 浏览器下有效):</p>
<div class="test" style="text-overflow:'>>';">This is some long text that will not fit in the box</div>
</body>
</html>

作者:terry,如若转载,请注明出处:https://www.web176.com/css3textpro/5151.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2022年1月17日 下午4:11
下一篇 2022年1月17日 下午4:18

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注