javascript - 如何在同一行上获得多个具有不同 ID 的进度条?
问题描述
我有一个 Bootstrap 进度条,显示用户的熟练程度(基本上,对尝试的正确响应)。但是,我想用两个条来着色差异,一个标记为“bg-success”,另一个标记为“bg-warning”,以使对比更加明显。我用不同 ID 的进度条做到了这一点。问题是进度条不会出现在同一行。
下面的代码显示了我的位置,并且我尝试了所有可以修复的重新标记尝试,但无济于事。
以下是相关的 JavaScript:
function setBars() {
var profPerc = Number(((myProg[1] / myProg[2]) * 100).toFixed(csvSize.toString().length));
document.getElementById("profBar").innerHTML = "<strong>" + profPerc.toString() + "</strong>";
document.getElementById("profBar").style.width = profPerc + "%";
document.getElementById("offBar").innerHTML = "<strong> </strong>";
document.getElementById("offBar").style.width = (100 - profPerc) + "%";
}
// There are no errors with any of the other above-mentioned variables.
这是相关的HTML:
<div class="proficiencydiv">
<div class="progress-bar bg-success" role="progressbar" id="profBar" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-warning" role="progressbar" id="offBar" aria-valuemin="0" aria-valuemax="100"></div>
</div>
我希望得到如下所示的结果:
"[profBar][offBar]".
相反,我得到:
"[profBar]"
"[offBar]"
解决方案
在css下面添加
.proficiencydiv{
display: flex}
.proficiencydiv{
display: flex}
.proficiencydiv div{
margin: 10px}
<div class="proficiencydiv">
<div class="progress-bar bg-success" role="progressbar" id="profBar" aria-valuemin="0" aria-valuemax="100">profBar</div>
<div class="progress-bar bg-warning" role="progressbar" id="offBar" aria-valuemin="0" aria-valuemax="100">offBar</div>
</div>
推荐阅读
- postgresql - AWS 上的 Postgres 11.8 在 15 分钟后失去连接/终止查询,没有通知或错误
- mysql - 适用于 Oracle 的触发器,我正在尝试生成 MySQL 等价物
- php - PHP FPM 不从 php.ini 加载更改
- java - Android问题加载小部件-logcat中没有错误
- excel - excel中是否有公式来查找row1中的两个字母单元格是否存在于row2和3中?
- java - Java - Ecipe IDE 错误 - 引导层初始化期间发生错误
- r - 在 R 中遇到问题
- javascript - 如何对数组对象进行分组以获得所需的数据格式?
- r - 用每条/组的观察数注释 ggplot boxplot facets
- python - 从 sys.path 中删除路径