::綠細胞雜誌::

Would you like to react to this message? Create an account in a few clicks or log in to continue.

紀錄生活一切雜事


    純CSS文字超出省略號效果,支持IE/FF

    grass0423
    grass0423
    Admin


    文章數 : 122
    注冊日期 : 2010-02-23

    純CSS文字超出省略號效果,支持IE/FF Empty 純CSS文字超出省略號效果,支持IE/FF

    發表  grass0423 周五 1月 28, 2011 4:05 pm

    CSS版
    純CSS文字超出省略號效果,支持IE/FF Aoc_810

    代碼:
    <!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=utf-8" />
    <title>JS test</title>
    <style type="text/css">
    *{
          margin:0;
          padding:0;
    }
    body{
          padding:10px;
          font-family:Arial;
    }
    #ididid{
          position:relative;
          width:150px;
          height:20px;
          line-height:20px;
          text-overflow:ellipsis;
          white-space:normal;
          *white-space:nowrap;
          overflow:hidden;
          border:1px solid #999;
    }
    #ididid span{
          position:absolute;
          top:0;
          right:0;
          display:block;
          float:left;
    }
    #ididid span:after{content:"...";}
    </style>
    </head>
    <body>
    <div id="ididid">test test test test test test test test test test test test test test test test test test test test test test test <span></span></div>
    </body>
    </html>


    js版
    代碼:
    <!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=utf-8" />
    <title>JS test</title>
    <style type="text/css">
    *{
       margin:0;
       padding:0;
    }
    body{
       padding:10px;
       font-family:Arial;
    }
    #ididid{
       width:150px;
       line-height:20px;
       overflow:hidden;
       border:1px solid #999;
    }
    </style>
    </head>
    <body>
    <script type="text/javascript">
    function testAuto(thisId,needLeng){
       var ididid = document.getElementById(thisId);
       var nowLeng = ididid.innerHTML.length;
       if(nowLeng > needLeng){
          var nowWord = ididid.innerHTML.substr(0,needLeng)+'...';
          ididid.innerHTML = nowWord;
       }
    }
    </script>
    <div id="ididid">12345678901234567890test test test test test test test test test test test test test test test test test test test test test test test</div>
    <script type="text/javascript">
    testAuto('ididid',15)
    </script>
    </body>
    </html>

      現在的時間是 周四 9月 19, 2024 10:34 am