Html 向水平条形图添加标签
我是HTML新手。在下表中,如何添加一些标签,例如Html 向水平条形图添加标签,html,css,Html,Css,我是HTML新手。在下表中,如何添加一些标签,例如 Team 1up Team blue Team tigers Team watermelon Team crazyred Team Melt 在图表的左侧,轨迹是否完全对齐 $(函数(){ $('.progress fill span')。每个(函数(){ var percent=$(this.html(); $(this.parent().css('width',percent)); }); }); 正文{ 背景:#999; } .集装箱
Team 1up
Team blue
Team tigers
Team watermelon
Team crazyred
Team Melt
在图表的左侧,轨迹是否完全对齐
$(函数(){
$('.progress fill span')。每个(函数(){
var percent=$(this.html();
$(this.parent().css('width',percent));
});
});代码>
正文{
背景:#999;
}
.集装箱{
宽度:500px;
利润率:20px;
背景:#fff;
填充:20px;
溢出:隐藏;
浮动:左;
}
.水平.进度条{
浮动:左;
高度:18px;
宽度:100%;
填充:3px0;
}
.水平。进度跟踪{
位置:相对位置;
宽度:100%;
高度:20px;
背景:#ebebeb;
}
.水平。进度填充{
位置:相对位置;
背景:#666;
高度:20px;
宽度:50%;
颜色:#fff;
文本对齐:居中;
字体系列:“Lato”,“Verdana”,无衬线;
字体大小:12px;
线高:20px;
}
团队表现
100%
75%
60%
20%
34%
82%
像这样的东西,先生
我只是将这些条向右浮动,将宽度减小到80%,并为相关文本创建了另一个跨度
<div class="progress-bar horizontal">
<span class="name">Team Name</span>
<div class="progress-track">
<div class="progress-fill">
<span>75%</span>
</div>
</div>
您可以创建一个名为进度组
的组件,并将进度标签
和进度条
放入其中<代码>进度组
负责儿童调整。我使用了flex,这在本例中很有意义。如果您想在将来添加额外的组件,这将为您提供更多的控制
团队表现
第1队
100%
蓝队
75%
老虎队
60%
西瓜队
20%
团队疯狂
34%
团队融合
82%
身体{
背景:#999;
}
.集装箱{
宽度:500px;
利润率:20px;
背景:#fff;
填充:20px;
溢出:隐藏;
浮动:左;
}
.水平.进度条{
浮动:左;
高度:18px;
宽度:100%;
填充:3px0;
}
.水平。进度跟踪{
位置:相对位置;
宽度:100%;
高度:20px;
背景:#ebebeb;
}
.水平。进度填充{
位置:相对位置;
背景:#666;
高度:20px;
宽度:50%;
颜色:#fff;
文本对齐:居中;
字体系列:“Lato”,“Verdana”,无衬线;
字体大小:12px;
线高:20px;
}
.进步小组{
显示器:flex;
}
.进度标签{
宽度:170px;
文本对齐:右对齐;
右边填充:10px;
}
.进度标签::之后{
内容:“:”;
}
$(函数(){
$('.progress fill span')。每个(函数(){
var percent=$(this.html();
$(this.parent().css('width',percent));
});
});
非常感谢。如何使标签正确对齐.name{text align:right;display:inline block}
在此处不起作用。只需在.horizontal.progress轨迹中从右向左更改浮动即可。已在主答案中编辑。抱歉,请求不明确。我是说像这样的文本对齐。非常感谢。你能帮我回答这个问题吗@ar2015听起来已经有了一个很好的答案bro:D
body {
background: #999;
}
.container {
width: 500px;
margin: 20px;
background: #fff;
padding: 20px;
overflow: hidden;
float: left;
}
.horizontal .progress-bar {
float: right;
height: 18px;
width: 100%;
padding: 3px 0;
}
.horizontal .progress-track {
position: relative;
float: left;
width: 80%;
height: 20px;
background: #ebebeb;
}
.horizontal .progress-fill {
position: relative;
background: #666;
height: 20px;
width: 50%;
color: #fff;
text-align: center;
font-family: "Lato","Verdana",sans-serif;
font-size: 12px;
line-height: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container horizontal flat">
<h2>Team performances</h2>
<div class="progress-group">
<div class="progress-label">Team 1up</div>
<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>100%</span>
</div>
</div>
</div>
</div>
<div class="progress-group">
<div class="progress-label">Team blue</div>
<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>75%</span>
</div>
</div>
</div>
</div>
<div class="progress-group">
<div class="progress-label">Team tigers</div>
<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>60%</span>
</div>
</div>
</div>
</div>
<div class="progress-group">
<div class="progress-label">Team watermelon</div>
<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>20%</span>
</div>
</div>
</div>
</div>
<div class="progress-group">
<div class="progress-label">Team crazyred</div>
<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>34%</span>
</div>
</div>
</div>
</div>
<div class="progress-group">
<div class="progress-label">Team Melt</div>
<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>82%</span>
</div>
</div>
</div>
</div>
</div>
body {
background: #999;
}
.container {
width: 500px;
margin: 20px;
background: #fff;
padding: 20px;
overflow: hidden;
float: left;
}
.horizontal .progress-bar {
float: left;
height: 18px;
width: 100%;
padding: 3px 0;
}
.horizontal .progress-track {
position: relative;
width: 100%;
height: 20px;
background: #ebebeb;
}
.horizontal .progress-fill {
position: relative;
background: #666;
height: 20px;
width: 50%;
color: #fff;
text-align: center;
font-family: "Lato","Verdana",sans-serif;
font-size: 12px;
line-height: 20px;
}
.progress-group {
display: flex;
}
.progress-label {
width: 170px;
text-align: right;
padding-right: 10px;
}
.progress-label::after {
content: ":";
}
$(function() {
$('.progress-fill span').each(function(){
var percent = $(this).html();
$(this).parent().css('width', percent);
});
});