隨筆-199  評論-203  文章-11  trackbacks-0
          我們在瀏覽網頁的時候,常常會看到某些網站的文章標題由于過長而只顯示一部分,另一部分用省略號來表示,這是為了防止標題過長而導致頁面排版不好 看。那么這個文章標題省略號是如何實現的呢?目前常見的方法是通過動態語言程序來控制,判斷標題的長度,然后截取部分來顯示,其余的用省略號顯示,這樣往 往在英文和中文的長度上難以判斷。今天在網上看到可以用CSS來實現,效果還不錯,拿來分享。

              CSS實現截斷過長標題文字的原理非常簡單,就是設置一個寬度,然后超過這個寬度值的內容就隱藏,并用省略號來顯示。用到的就是text- overflow:ellipsis,在IE下顯示是正確的,超出部分為省略號...,而在Firefox中超出部分卻是裁切掉了,有的文字就顯示一半, 很不好看,這是因為Firefox不支持text- overflow:ellipsis屬性。為了讓Firefox中也能顯示省略號,所以要外加一個xml文件。下面直接給出兼容IE和Firefox的代 碼:

          <!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>使用CSS截斷過長標題文字的方法-HTMer</title>
          <style type="text/css">
          <!--
          .htmer
          {
          width
          : 200px;
          white-space
          : nowrap;
          overflow
          : hidden;
          text-overflow
          :ellipsis;      /*兼容IE*/
          -moz-binding
          : url('ellipsis.xml#ellipsis');      /*兼容Firefox,調用ellipsis.xml文件,注意ellipsis.xml文件路徑*/
          }
          -->
          </style>
          </head>
          <body>
          <div class="htmer">使用CSS截斷過長標題文字的方法-HTMer</div>
          </body>
          </html>

          ellipsis.xml文件源代碼:

          <?xml version="1.0"?>
          <bindings
            
          xmlns="http://www.mozilla.org/xbl"
            xmlns:xbl
          ="http://www.mozilla.org/xbl"
            xmlns:xul
          ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          >
          <binding id="ellipsis">
              
          <content>
                  
          <xul:description crop="end" xbl:inherits="value=xbl:text"><children/></xul:description>
              
          </content>
          </binding>
          </bindings>
          posted on 2011-01-17 11:13 Werther 閱讀(2322) 評論(1)  編輯  收藏 所屬分類: 11.JavaScript

          評論:
          # re: 使用CSS截斷過長文字的方法 2016-03-08 12:21 | 12312312
          測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試測試測試測試彩色測試  回復  更多評論
            

          I'm reading...

          Java 60

          Head  First SQL

          寶貝連接


          If you need these books,pls send me emails.
          Email:kunpeng.niu@163.com
          <2016年3月>
          282912345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          留言簿(10)

          隨筆分類(178)

          隨筆檔案(208)

          文章檔案(1)

          新聞檔案(6)

          相冊

          1.Java Official Website

          2.Java Study Website

          3.Java Technic Website

          4.Java Video Website

          5.Database Website

          6.Bookshop Website

          7.English Website

          8.Friends Link

          9.Other Web

          積分與排名

          • 積分 - 685095
          • 排名 - 67

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 贵阳市| 万载县| 清徐县| 富民县| 卓尼县| 新龙县| 历史| 张掖市| 石渠县| 桃园市| 五峰| 柏乡县| 德江县| 新疆| 杨浦区| 仙游县| 龙海市| 高台县| 蒙自县| 灵川县| 永嘉县| 汉沽区| 白河县| 宜城市| 项城市| 会同县| 浦城县| 乐都县| 江源县| 武宣县| 东海县| 桐柏县| 穆棱市| 当阳市| 澎湖县| 都昌县| 贡嘎县| 拉孜县| 丰原市| 志丹县| 玛沁县|