CSS中的text-overflow:clip|ellipsis的使用


如果想讓某個容器(div或者li或者...塊級元素)顯示一行文字,當文字內容過多時,不換行,而是出現...,可以使用text-overflow:clip|ellipsis
基本語法:text-overflow : clip | ellipsis
若為text-overflow:clip  取默認值,不顯示省略標記(...),而是簡單的裁切
若為text-overflow:ellipsis  當對象內文本溢出時顯示省略標記(...)  
例如:
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <style type="text/css">
	#box{
		width:100px;
		background-color:#87CEEB;
		overflow:hidden;
		text-overflow:ellipsis;
		white-space:nowrap;
	}   
  </style>
 </head>
 <body>
  <div id="box">helloworldhelloworldhelloworldhelloworldhelloworldhelloworld</div>
 </body>
</html>

注:overflow: hidden; text-overflow:ellipsis;white-space:nowrap;一定要一起用

1.一定要給容器定義寬度.

2.如果少了overflow: hidden;文字會橫向撐到容易的外面

3.如果少了white-space:nowrap;文字會把容器的高度往下撐;即使你定義了高度,省略號也不會出現,多余的文字會被裁切掉

4.如果少了text-overflow:ellipsis;多余的文字會被裁切掉,就相當於你這樣定義text-overflow:clip.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM