当前位置: css > DIV+CSS实例 >

使用纯css制作的进度条和柱状图

时间:2010-01-18 21:18来源:CSS中国 作者:snowbiao 点击:
本文使用 css 实现 进度条 与柱状图的制作,效果很酷,不信可以先来看看效果图: 以上的进度条,是基于div+css实现。 下面讲解制作方法: CSS代码: .graph{ position : relative ; width : 200p

本文使用css实现进度条与柱状图的制作,效果很酷,不信可以先来看看效果图:

CSS制作进度条和柱状图
CSS制作进度条和柱状图

以上的进度条,是基于div+css实现。

下面讲解制作方法:

CSS代码:

  1. .graph {   
  2.     positionrelative;   
  3.     width200px;   
  4.     border1px solid #B1D632;   
  5.     padding2px;   
  6.     margin-bottom: .5em;                      
  7. }  
  8. .graph .bar {   
  9.     displayblock;      
  10.     positionrelative;  
  11.     background#B1D632;   
  12.     text-aligncenter;   
  13.     color#333;   
  14.     height2em;   
  15.     line-height2em;                                      
  16. }  
  17. .graph .bar span { positionabsolute; left: 1em; } 

HTML代码:

  1. <h3>简单进度条</h3> 
  2. <div class="graph"> 
  3. <strong class="bar" style="width: 54%;"><span>54%</span></strong> 
  4. </div>      
  5. <div class="graph"> 
  6. <strong class="bar" style="width: 8%;"><span>8%</span></strong></div> 

 只要改变bar的width就可以随意改变进度条的长度.

下面是复杂那个效果的制作方法:

CSS代码:

  1. /* 复杂进度条 */ 
  2.  dl {   
  3.      margin0;   
  4.      padding0;                       
  5.  }  
  6.  dt {   
  7.      positionrelative;  
  8.      clearboth;  
  9.      displayblock;   
  10.      floatleft;   
  11.      width104px;   
  12.      height20px;   
  13.      line-height20px;  
  14.      margin-right17px;                
  15.      font-size: .75em;   
  16.      text-alignright;   
  17.  }  
  18.  dd {   
  19.      positionrelative;   
  20.      displayblock;                   
  21.      floatleft;       
  22.      width197px;   
  23.      height20px;   
  24.      margin0 0 15px;   
  25.      backgroundurl("g_colorbar.jpg");   
  26.  }  
  27.  * html dd { floatnone; } /*此处为 IE hack */ 
  28.    
  29.  dd div {   
  30.      positionrelative;   
  31.      backgroundurl("g_colorbar2.jpg");   
  32.      height20px;   
  33.      width75%;   
  34.      text-align:right;   
  35.  }  
  36.  dd div strong {   
  37.      positionabsolute;   
  38.      right: -5px;   
  39.      top: -2px;   
  40.      displayblock;   
  41.      backgroundurl("g_marker.gif");   
  42.      height24px;   
  43.      width9px;   
  44.      text-alignleft;  
  45.      text-indent-9999px;   
  46.      overflowhidden;  
  47.  } 

HTML 代码:

  1. <h3>复杂进度条</h3> 
  2. <dl> 
  3.     <dt>喜欢博客园</dt> 
  4.     <dd> 
  5.         <div style="width:25%;"><strong>25%</strong></div> 
  6.     </dd> 
  7.     <dt>很喜欢</dt> 
  8.     <dd> 
  9.         <div style="width:55%;"><strong>55%</strong></div> 
  10.     </dd> 
  11.     <dt>超级喜欢</dt> 
  12.     <dd> 
  13.         <div style="width:75%;"><strong>75%</strong></div> 
  14.     </dd> 
  15. </dl> 

CSS中用到了几个图片在示例代码下载下载中有.

下面是柱状图的制作。

柱状图的效果图:

CSS柱状图
 
 
 


顶一下
(2)
100%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片
推荐内容
赞助商