天天看點

CSS3 用text-overflow解決文字排版問題

基本文法

text-overflow的使用需配合hight,over-flow:hidden;white-space:nowrap;三個屬性共同使用

text-overflow: clip;ellipsis;string

clip: 直接隐藏不顯示

ellipse: 用… 三個點來表示溢出的文字 (常用)

string:可自定義符号來表示放不下的字元

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
	<style type="text/css">
		.tf{
			width: 100px;
			height:50px;
			border:1px solid black;
			overflow: hidden;
			text-overflow: clip;/*如果隻是單純的隐藏的話,加不加這句話效果都一樣  height+overflow就可對溢出的文字直接隐藏*/
		}
		.tf1{
			width: 100px;
			border:1px solid black;
			overflow: hidden;
			text-overflow: ellipsis;
			-webkit-text-overflow: ellipsis;
			white-space: nowrap;
			/*若使用ellipsis屬性     
				text-overflow:ellipsis; overflow: hidden;white-space: nowrap;
			 這三個屬性缺一不可
			*/
		}
	</style>
</head>
<body>
	<div class="tf">
		新浪網新聞中心是新浪網最重要的頻道之一,24小時滾動報道國内、國際及社會新聞。每日編發新聞數以萬計。
	</div>

	<div class="tf1">
		新浪網新聞中心是新浪網最重要的頻道之一,24小時滾動報道國内、國際及社會新聞。每日編發新聞數以萬計。
	</div>

	
</body>
</html>