overflow的使用

css屬性中,有着衆多的小技巧,一直覺得overflow是其中一個,在主頁顯示顯示小標題時,我們可以使用它來顯示內容,避免產生換行從而使內容看起來噁心,當然,一般的網站主頁在後臺都會對標題的長度作出限定長度,然而,往往幾個字不能準確描述新聞或文章的概要,這時可以考慮使用overflow這個屬性

實現如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>text-overflow</title>
</head>
<body>
<style type="text/css">
  .test_demo_clip{text-overflow:clip; overflow:hidden; white-space:nowrap; width:200px; background:green;}
  .test_demo_ellipsis{text-overflow:ellipsis; overflow:hidden; white-space:nowrap; width:200px; background:green;}
  div{
  	margin: 15px 0;
  }
</style>
<h2>text-overflow : clip </h2>
<div>不顯示省略標記,而是簡單的裁切條</div>
  <div class="test_demo_clip">
  不顯示省略標記,而是簡單的裁切條
</div>
<h2>text-overflow : ellipsis </h2>
<div>當對象內文本溢出時顯示省略標記</div>
<div class="test_demo_ellipsis">
  當對象內文本溢出時顯示省略標記
</div>
</body>
</html>

具體效果如下:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章