用CSS做条形图

Publish: 2009-10-30 14:40:29 Category: 一阳指

  在网上找了个Css做的条形图,可惜原代码中的图片丢失了,也不知原来是什么样的。我试着自己补上图片,并修改了一些CSS参数,想不到真是自己想要的方式。这段代码和图片只有在6%-96之间显示得完美,在其它范围就有些变形了,但对于我来说已经够了。

 

原代码记录下:

  1. <style> 
  2.     dl {   
  3.         margin: 10px 0px 10px 0px;   
  4.         padding:  10px 0px -5px 0px;  
  5.         background-color:#484848;  
  6.         width: 330px;  
  7.     }  
  8.     dt {   
  9.         position: relative; /* IE is dumb */  
  10.         clear: both;  
  11.         display: block;   
  12.         float: left;   
  13.         width: 60px;   
  14.         height: 20px;   
  15.         line-height: 20px;  
  16.         margin-right: 17px;                
  17.         font-size: .75em;   
  18.         text-align: right;   
  19.         color: #fff;   
  20.     }  
  21.     dd {   
  22.         position: relative; /* IE is dumb */  
  23.         display: block;        
  24.         float: left;       
  25.         width: 240px;   
  26.         height: 20px;   
  27.         margin: 0 0 15px;   
  28.         background: url("g_colorbar.jpg");   
  29.      }  
  30.      * html dd { float: none; }   
  31.     /* IE is dumb; Quick IE hack, apply favorite filter methods for   
  32.     wider browser compatibility */  
  33.  
  34.      dd div {   
  35.         position: relative;   
  36.         background: url("g_colorbar2.jpg");   
  37.         height: 20px;   
  38.         width: 75%;   
  39.         text-align:right;   
  40.      }  
  41.      dd div strong {   
  42.         position: absolute;   
  43.         right: 0px;   
  44.         top: 0px;   
  45.         display: block;   
  46.         background: url("g_marker.gif");   
  47.         height: 20px;   
  48.         width: 7px;   
  49.         text-align: left;  
  50.         text-indent: -9999px;   
  51.         overflow: hidden;  
  52.      }  
  53. </style> 
  54. <dl> 
  55.     <dt>Cinner</dt> 
  56.     <dd> 
  57.         <div style="width:25%;"><strong>25%</strong></div> 
  58.     </dd> 
  59.     <dt>Tonyer</dt> 
  60.     <dd> 
  61.         <div style="width:55%;"><strong>55%</strong></div> 
  62.     </dd> 
  63.     <dt>Bill Gates</dt> 
  64.     <dd> 
  65.         <div style="width:96%;"><strong>75%</strong></div> 
  66.     </dd> 
  67. </dl> 

用的图片有三张:


可以到这里查看实例。

标签: css, 图表, 代码

评论列表 »

  1. oyster 2009-11-9 14:02:47

    恩 很不 错的 说 误差是跟图片本身宽度相关的 可以 再精确。

  2. 开心凡人 2009-11-2 21:18:03

    又学了一招啊,啊哈哈

    做点有个性的图表还是不错的。

  3. 帅豆 2009-10-31 20:12:32

    我太惭愧了……

    。。。。。。。。

  4. canaan 2009-10-31 18:24:13

    厉害,不懂

    网上找的,我可做不出来。

  5. 先看看 2009-10-31 15:13:59

    这个方法的确不错

    网上找的。

  6. 古墓候梅 2009-10-31 15:09:12

    不是很懂.

    我也不太懂。

  7. 老饕 2009-10-30 21:49:56

    你哪来这个做什么用的?

    看About。

  8. Louis Han 2009-10-30 15:43:18

    暂时没有这个需求

    随便搞搞。

1/1, 8«1»

添加新评论 »