【发布时间】:2014-11-30 15:34:07
【问题描述】:
我正在尝试将具有多个百分比值 (see docs example) 的 bootstrap 3 进度条放在一起。
所有值的组合值不能超过 100%,但是 django 正在四舍五入,我得到的值是 101%
#max_width = 100
#total.count = 17
#a.count = 11 (65%)
#b.count = 2 (12%)
#c.count = 4 (24%)
<div class="progress">
<div class="progress-bar" style="width: {% widthratio a.count total.count max_width %}%">
{{ a.count }} ({% widthratio a.count total.count max_width %}%)
</div>
<div class="progress-bar" style="width: {% widthratio b.count total.count max_width %}%">
{{ b.count }} ({% widthratio b.count total.count max_width %}%)
</div>
<div class="progress-bar" style="width: {% widthratio c.count total.count max_width %}%">
{{ c.count }} ({% widthratio c.count total.count max_width %}%)
</div>
</div>
输出
<div class="progress">
<div class="progress-bar" style="width: 65%">
11 (65%)
</div>
<div class="progress-bar" style="width: 12%">
2 (12%)
</div>
<div class="progress-bar" style="width: 24%">
4 (24%)
</div>
</div>
如您所见,所有百分比加起来为 101%,因此最后一个值不会显示在进度条中。有没有办法解决这个问题?
【问题讨论】:
标签: django twitter-bootstrap-3 django-templates