登录 注册

CSS条状图表形式的实现方法

资讯 驱动中国 668 次阅读 0 条评论
分享 Q

CSS条状图表是我们在网页设计中常常会遇到的一种形式。条状图表可以将数量,以条状图形的形式直观的表示出来。

CSS基本条状图表的实现方法是什么?我们看下面的实例介绍:

以下是引用片段:
<div class="graph">
    <strong class="bar" style="width: 24%;">24%</strong>
</div>


这是xhtml代码,定义了一个容器,应用类graph,其中包括了一个xhtml元素strong,并且对这个元素应用类bar。

我们看下面的CSS定义:

以下是引用片段:
.graph { 
        position: relative; /* IE is dumb */
        width: 200px; 
        border: 1px solid #B1D632; 
        padding: 2px; 
    }
    .graph .bar { 
        display: block;
        position: relative;
        background: #B1D632; 
        text-align: center; 
        color: #333; 
        height: 2em; 
        line-height: 2em;            
    }
    .graph .bar span { position: absolute; left: 1em; }


通过上面的边框,颜色的定义,我们勾勒出了一个条状的图形,我们在xhtml代码中style="width: 24%;",定义了所设置的区域既大小。这样一个基本的条状图表就完成了!

全部代码:

以下是引用片段:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>homepage.yesky.com</title>
<style type="text/css">
    .graph { 
        position: relative; /* IE is dumb */
        width: 200px; 
        border: 1px solid #B1D632; 
        padding: 2px; 
    }
    .graph .bar { 
        display: block;
        position: relative;
        background: #B1D632; 
        text-align: center; 
        color: #333; 
        height: 2em; 
        line-height: 2em;            
    }
    .graph .bar span { position: absolute; left: 1em; }
</style>
</head>
<body>
<div class="graph">
    <strong class="bar" style="width: 24%;">24%</strong>
</div>
<br />
<div class="graph">
    <strong class="bar" style="width: 60%;">60%</strong>
</div>
</body>
</html>

版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友