日期:2014-05-17  浏览次数:20594 次

使用CSS截断过长标题文字的方法

整理磁盘,发现这个小东东,发一文备忘。

测试文件test.html代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>使用CSS截断过长标题文字的方法</title>
<style type="text/css">
<!--
.htmer{
width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow:ellipsis;      /*兼容IE*/
}
-->
</style>
</head>
<body>
<div class="htmer">使用CSS截断过长标题文字的方法</div>
</body>
</html>

IE(V9.0)效果

chrome(V8.0.552)效果:

FireFox(V12.0)效果