当前位置:编程学习 > JS >>

CSS超过宽度显示省略号

CSS超过宽度显示省略号,这是个比较实用的小技巧,从事前端开发的朋友经学会遇到,为了页面美观整齐,我们一般会用CSS控制一行字体溢出时省略掉,为了获得用户体验,我们把溢出的部分用省略号代替,本代码就是实现了这样一个功能。仅供参考。
答案:<!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> 
  <title>纯CSS超过宽度显示省略号</title> 
    <style type="text/css"> 
       *{ margin:0; padding:0; font-size:12px; font-family:"新宋体";} 
        ol{ background:url() no-repeat left -2px;} 
        li{position:relative; padding:0 60px 0 20px; height:20px; overflow:hidden; line-height:20px; width:250px; 
           list-style:none;}
        li a{ position:relative;background: url(http://www.zzzyk.com/jscss/demoimg/201107/pot.gif) no-repeat
              230px top;display:inline-block; text-decoration:none; color:#000; padding-right:12px; margin-right:10px;} 
        li a:hover{ text-decoration:underline;} 
        li a em{width:10px; height:18px; overflow:hidden;background:#FFF; position:absolute;right:0; bottom:0; 
             text-indent:-999px;} li span{ position:absolute; padding-left:5px; color:#CCC;}
    </style> 
  </head> 
<body> 
  <ol> 
    <li><a href="#">红歌练演员,我们走在大路上<em>...</em></a><span> 2011-6-21</span></li>
    <li><a href="#">站长资源库提供编程源码、网站源码、网页素材、书籍教程、网站模板、网页特效代码等,做有质量的学习型源码下载站。< em>...</em></a><span>2011-6-21</span></li>
  </ol>
</body> 
</html>

上一个:CSS美化Calendar日历的雏形,并无日历功能
下一个:超小代码实现文字动画,出自1K写出3D圣诞树的作者

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,