©
本文档使用
php中文网手册 发布
text-overflow:clip | ellipsis
默认值:clip
适用于:块级容器元素
继承性:无
动画性:否
计算值:指定值
clip:当内联内容溢出块容器时,将溢出部分裁切掉。
ellipsis:当内联内容溢出块容器时,将溢出部分替换为(...)。
非visible时,定义内联内容溢出其块容器是否截断或者添加(...)及自定义字符
要使得 <' text-overflow '> 属性生效,块容器必须显式定义 <' overflow '> 为非visible值,同时显式或者隐式的定义 <' width '> 为非auto值, <' white-space '> 为nowrap值。
用代码来解释这段话:
case 1:
<style> .demo p{overflow:hidden;width:200px;white-space:nowrap;text-overflow:ellipsis;} </style> <div class="demo"> <p>这是一句非常非常长的话,被用来做text-overflow属性测试。</p> </div>
case 1,我们将text-overflow生效必备的3个属性: <' overflow '> , <' width '> 和 <' white-space '> 都直接定义在了内联内容的父级块容器上
case 2:
<style>
.demo{width:200px;white-space:nowrap;}
.demo p{overflow:hidden;text-overflow:ellipsis;}
</style>
<div class="demo">
<p>这是一句非常非常长的话,被用来做text-overflow属性测试。</p>
</div>case 2,我们将 <' width '> 和 <' white-space '> 定义在了更外层的块容器上,但case 1和case 2的效果是一样的。因为这2个属性可以被继承
对应的脚本特性为textOverflow。
| Values | IE | Firefox | Chrome | Safari | Opera | iOS Safari | Android Browser | Android Chrome |
|---|---|---|---|---|---|---|---|---|
| Basic Support | 6.0+ | 2.0-6.0 | 4.0+ | 6.0+ | 15.0+ | 6.0+ | 2.1+ | 18.0+ |
| 7.0+ |
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="utf-8" />
<title>text-overflow_CSS参考手册_web前端开发参考手册系列</title>
<meta name="author" content="Joy Du(飘零雾雨), dooyoe@gmail.com, www.doyoe.com" />
<style>
.test li{margin-top:10px;}
.test .clip p{overflow:hidden;width:200px;white-space:nowrap;text-overflow:clip;}
.test .ellipsis p{overflow:hidden;width:200px;white-space:nowrap;text-overflow:ellipsis;}
</style>
</head>
<body>
<ul class="test">
<li class="clip">
<strong>clip: 直接将溢出的文字裁剪</strong>
<p>测试用文字测试用文字测试用文字测试用文字测试用文字测试用文字</p>
</li>
<li class="ellipsis">
<strong>ellipsis: 将溢出的文字显示省略标记(...)</strong>
<p>测试用文字测试用文字测试用文字测试用文字测试用文字测试用文字</p>
</li>
</ul>
</body>
</html>
点击 "运行实例" 按钮查看在线实例