gpt4 book ai didi

html - 向水平条形图添加标签

转载 作者:太空宇宙 更新时间:2023-11-04 15:48:43 24 4
gpt4 key购买 nike

我是 HTML 新手。在下面的图表中,如何添加一些标签,例如

Team 1up
Team blue
Team tigers
Team watermelon
Team crazyred
Team Melt

图表左边的轨道全部右对齐?

$(function() {
$('.progress-fill span').each(function(){
var percent = $(this).html();
$(this).parent().css('width', percent);
});
});
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;
}
<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-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>100%</span>
</div>
</div>
</div>

<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>75%</span>
</div>
</div>
</div>

<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>60%</span>
</div>
</div>
</div>

<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>20%</span>
</div>
</div>
</div>

<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>34%</span>
</div>
</div>
</div>

<div class="progress-bar horizontal">
<div class="progress-track">
<div class="progress-fill">
<span>82%</span>
</div>
</div>
</div>
</div>

最佳答案

您可以创建一个名为progress-group 的组件,并将progress-labelprogress-bar 放入其中。 progress-group 负责 child 对齐。我使用了 flex,这在这种情况下很有意义。如果你想在未来添加额外的组件,这会给你更多的控制权。

https://codepen.io/anon/pen/oPVyYm

<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);
});
});

关于html - 向水平条形图添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52445036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com