CSS实例(五):简洁的栏目实现方式

今天花了点儿时间,琢磨了一下如何简洁的实现网页上常用的栏目。就是下面的这种东西,我称之为栏目,不知道别人叫它什么:



  以下是我的HTML文件及CSS文件,可以便捷地进行样式切换。如果谁有更简洁的方式,请留言指教。

   HTML文件:
Html代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  6. <title>Insert title here</title>  
  7. <link href="column.css" style="text/css" rel="stylesheet"/>  
  8. <script type="text/javascript">  
  9.     var gIndex = 1;  
  10.     function doSwitch(){  
  11.         var e = document.getElementById('info');  
  12.         /*下面的变量是e,代码高亮好像有个BUG,阅读请注意。*/  
  13.         ee.className = e.className.split(' ')[0]+' s'+(gIndex%3+1);  
  14.         gIndex++;  
  15.     }  
  16. </script>  
  17. </head>  
  18. <body>  
  19. <ul class="column s1" id="info">  
  20.     <li class="title"><div>信息公示</div></li>  
  21.     <li><a href="#">CSS</a></li>  
  22.     <li><a href="http://wallimn.iteye.com">http://wallimn.iteye.com</a></li>  
  23.     <li><a href="#">很长文本自动截断,一切皆有可能,一切皆有可能,一切皆有可能,一切皆有可能</a></li>  
  24.     <li class="tail"><a href="#">更多...</a></li>  
  25. </ul>  
  26. <br/>  
  27. <input type="button" value="样式切换" onclick="doSwitch()" />  
  28. </body>  
  29. </html>  


   CSS文件:
Html代码   收藏代码
  1. ul.column{  
  2.     padding:0;  
  3.     margin:0;  
  4.     font:normal 12px "宋体";  
  5.     border:1px solid #000;  
  6. }  
  7. ul.column li{  
  8.     height:26px;  
  9.     line-height:26px;  
  10.     margin:0 4px;  
  11.     border-bottom:1px dashed #ccc;  
  12.     vertical-align:middle;  
  13.     padding-left:24px;  
  14.     white-space:nowrap;  
  15.     text-overflow:ellipsis;  
  16.     overflow:hidden;  
  17. }  
  18. ul.column li,ul.column li.title div{  
  19.     background:url("column.gif") no-repeat;  
  20. }  
  21. ul.column li a{  
  22.     text-decoration:none;  
  23. }  
  24. ul.column li a:hover{  
  25.     color:red;  
  26. }  
  27. ul.column li.title,ul.column li.tail{  
  28.     border-width:0;  
  29. }  
  30. ul.column li.title{  
  31.     background-repeat:repeat-x;  
  32.     margin:0;  
  33.     padding:0;  
  34. }  
  35. ul.column li.tail{  
  36.     text-align:right;  
  37.     padding-right:12px;  
  38.     background-image:none;  
  39. }  
  40.   
  41. /*1*/  
  42. ul.s1{  
  43.     width:300px;  
  44. }  
  45. ul.s1,ul.s1 li{  
  46.     border-color:#2e9803;  
  47. }  
  48. ul.s1 li{  
  49.     background-position: 0 -52px;  
  50. }  
  51. ul.s1 li.title{  
  52.     background-position: 0 -26px;  
  53. }  
  54. ul.s1 li.title div{  
  55.     background-position: 0 0;  
  56.     padding-left:24px;  
  57. }  
  58. /*2*/  
  59. ul.s2{  
  60.     width:300px;  
  61. }  
  62. ul.s2,ul.s2 li{  
  63.     border-color:#9438d4;  
  64. }  
  65. ul.s2 li{  
  66.     background-position: 0 -130px;  
  67. }  
  68. ul.s2 li.title{  
  69.     background-position: 0 -104px;  
  70. }  
  71. ul.s2 li.title div{  
  72.     background-position: 0 -78px;  
  73.     padding-left:24px;  
  74. }  
  75. /*3*/  
  76. ul.s3{  
  77.     width:300px;  
  78. }  
  79. ul.s3,ul.s3 li{  
  80.     border-color:#9bb8d2;  
  81. }  
  82. ul.s3 li{  
  83.     background-position: 0 -208px;  
  84. }  
  85. ul.s3 li.title{  
  86.     background-position: 0 -182px;  
  87. }  
  88. ul.s3 li.title div{  
  89.     background-position: 0 -156px;  
  90.     padding-left:24px;  
  91. }  


   用到的图片:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值