CSS文字截取功能實(shí)現(xiàn)代碼
更新時(shí)間:2008年06月26日 22:26:20 作者:
用css來實(shí)現(xiàn)自動(dòng)截取文字,不需要后臺(tái)程序和JS的使用。
好處是:
兼容IE,firefox,Opera;
有利于內(nèi)容完整性;有利于SEO;
無需后臺(tái)程序處理;
可以在前臺(tái)隨時(shí)調(diào)節(jié)要截取的長(zhǎng)度。
不好的地方:
不能自動(dòng)判斷截取長(zhǎng)度,當(dāng)字符很短的時(shí)候在Firefox中也會(huì)生成后面的省略符號(hào)。
另外在設(shè)置截取寬度的時(shí)候,要注意,盡量讓文字截取完整。
Quote:
<!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=utf-8" />
<title>css文字截取</title>
<style type="text/css">
body{font-size:13px;color:#8c966b;}
div{clear:both;width:340px;border:1px solid #333;margin:3px;padding:3px;}
div a{color:#8c966b;text-decoration:none;}
div a:hover{text-decoration:underline;}
div a{display:block;width:310px;white-space:nowrap;overflow:hidden;float:left;
-o-text-overflow: ellipsis; /* for Opera */
text-overflow:ellipsis; /* for IE */
}
div:after{content:"...";padding-left:3px;font-size:12px;}/* for Firefox */
</style>
</head>
<body>
用css來實(shí)現(xiàn)自動(dòng)截取文字,不需要后臺(tái)程序和JS的使用
好處是:有利于內(nèi)容完整性,有利于SEO,無需后臺(tái)程序處理,可以在前臺(tái)隨時(shí)調(diào)節(jié)要截取的長(zhǎng)度。
<div><a href="#">不好的地方:不能自動(dòng)判斷截取長(zhǎng)度,當(dāng)字符很短的時(shí)候在Firefox中也會(huì)生成后面的省略符號(hào)。</a></div>
<div><a href="#">另外在設(shè)置截取寬度的時(shí)候,要注意,盡量讓文字截取完整</a></div>
</body>
</html>
兼容IE,firefox,Opera;
有利于內(nèi)容完整性;有利于SEO;
無需后臺(tái)程序處理;
可以在前臺(tái)隨時(shí)調(diào)節(jié)要截取的長(zhǎng)度。
不好的地方:
不能自動(dòng)判斷截取長(zhǎng)度,當(dāng)字符很短的時(shí)候在Firefox中也會(huì)生成后面的省略符號(hào)。
另外在設(shè)置截取寬度的時(shí)候,要注意,盡量讓文字截取完整。
Quote:
<!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=utf-8" />
<title>css文字截取</title>
<style type="text/css">
body{font-size:13px;color:#8c966b;}
div{clear:both;width:340px;border:1px solid #333;margin:3px;padding:3px;}
div a{color:#8c966b;text-decoration:none;}
div a:hover{text-decoration:underline;}
div a{display:block;width:310px;white-space:nowrap;overflow:hidden;float:left;
-o-text-overflow: ellipsis; /* for Opera */
text-overflow:ellipsis; /* for IE */
}
div:after{content:"...";padding-left:3px;font-size:12px;}/* for Firefox */
</style>
</head>
<body>
用css來實(shí)現(xiàn)自動(dòng)截取文字,不需要后臺(tái)程序和JS的使用
好處是:有利于內(nèi)容完整性,有利于SEO,無需后臺(tái)程序處理,可以在前臺(tái)隨時(shí)調(diào)節(jié)要截取的長(zhǎng)度。
<div><a href="#">不好的地方:不能自動(dòng)判斷截取長(zhǎng)度,當(dāng)字符很短的時(shí)候在Firefox中也會(huì)生成后面的省略符號(hào)。</a></div>
<div><a href="#">另外在設(shè)置截取寬度的時(shí)候,要注意,盡量讓文字截取完整</a></div>
</body>
</html>
相關(guān)文章
推薦三種簡(jiǎn)潔的Tab導(dǎo)航(網(wǎng)頁選項(xiàng)卡)簡(jiǎn)析
推薦三種簡(jiǎn)潔的Tab導(dǎo)航(網(wǎng)頁選項(xiàng)卡)簡(jiǎn)析...2007-05-05用css alpha 濾鏡 實(shí)現(xiàn)input file 樣式美化代碼
用css alpha 濾鏡 實(shí)現(xiàn)input file 樣式美化代碼...2007-12-12