CSS實現讓的多餘的文字出現省略符號

來源:互聯網
上載者:User

我們在行列時,經常會出現一行文字超出了寬度,很多人使用了

 overflow:hidden  讓超出來的內容隱藏,有沒有一種代碼讓文字超出時,出現省略符號了?

答案是有

使用:white-space:nowrap;text-overflow:ellipsis; -o-text-overflow:ellipsis;

 

代碼示範:

 

代碼

<!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>設計源</title>
<style>
div.wid{ width:200px;white-space:nowrap;text-overflow:ellipsis; -o-text-overflow:ellipsis; overflow: hidden;}
</style>
</head>

<body>
<div class="wid"><a href="http://www.websjy.com/bbs/forumdisplay.php?fid=9" target="_blank">避免表格table和DIV被撐開變形的CSS代碼執行個體</a></div>
</body>
</html>

 

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.