用背景图片实现CSS柱状图表一例_DIV+CSS实例

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!
我们现在介绍,用背景图片的方法实现柱状图表。看下面的效果图:


  实现这样的图表并没有什么难处,我们看下面的xhtml代码:

示例代码 [www.mb5u.com]
<div id="vertgraph">
<ul>
<li class="critical" style="height: 150px;">22</li>
<li class="high" style="height: 80px;">7</li>
<li class="medium" style="height: 50px;">3</li>
<li class="low" style="height: 90px;">8</li>
<li class="info" style="height: 40px;">2</li>
</ul>
</div>

  这是一个无序列表,我们注重到,我们在xhtml中使用行内样式定义了不同的li的高度。
  我们在这一图表的制作中,需要使用两张图片,分别如下:




  我们看下面的css代码:

示例代码 [www.mb5u.com]
#vertgraph {
width: 378px;
height: 207px;
position: relative;
background: url("g_backbar.gif") no-repeat;
}
#vertgraph ul {
width: 378px;
height: 207px;
margin: 0;
padding: 0;
}
#vertgraph ul li {
position: absolute;
width: 28px;
height: 160px;
bottom: 34px;
padding: 0 !important;
margin: 0 !important;
background: url("g_colorbar3.jpg") no-repeat !important;
text-align: center;
font-weight: bold;
color: white;
line-height: 2.5em;
}
#vertgraph li.critical { left: 24px; background-position: 0px bottom !important; }
#vertgraph li.high { left: 101px; background-position: -28px bottom !important; }
#vertgraph li.medium { left: 176px; background-position: -56px bottom !important; }
#vertgraph li.low { left: 251px; background-position: -84px bottom !important; }
#vertgraph li.info { left: 327px; background-position: -112px bottom !important; }

  这段CSS代码就定义了这个柱状图表的显示,我们需要注重的是background-position属性的应用,这一属性是实现图表的要害.
  我们看最终的运行效果:

div css xhtml xml 代码调试框 代码调试框 [www.mb5u.com]

[ 可先修改部分代码 再运行查看效果 ]

  

来源:无忧整理//所属分类:DIV+CSS实例/更新时间:2007-03-23
相关DIV+CSS实例