为什么当我使用Bulma CSS框架(https://bulma.io/documentation/elements/progress/)
的进度时我在标签之间插入文字,但我没有看到任何价值。
<progress class="progress is-danger" value="90" max="100">90%</progress>
如何在Bulma的进度中添加文本?
答案 0 :(得分:3)
正常您没有看到值
<progress value="90" max="100">90%</progress>
没有内置解决方案。
但根据show-a-progress-bars-value-number-like-55-on-the-bar-by-using-css,以下是解决方案
progress.show-value {
position: relative;
}
progress.show-value:after {
content: attr(value)'%';
position: absolute;
top: 0;
left: 50%;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
font-size: calc(1rem / 1.5);
line-height: 1rem;
}
progress.show-value.is-small:after {
font-size: calc(0.75rem / 1.5);
line-height: 0.75rem;
}
progress.show-value.is-medium:after {
font-size: calc(1.25rem / 1.5);
line-height: 1.25rem;
}
progress.show-value.is-large:after {
font-size: calc(1.5rem / 1.5);
line-height: 1.5rem;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css" rel="stylesheet" />
<progress class="progress is-danger is-small show-value" value="90" max="100">90%</progress>
<progress class="progress is-danger show-value" value="90" max="100">90%</progress>
<progress class="progress is-danger is-medium show-value" value="90" max="100">90%</progress>
<progress class="progress is-danger is-large show-value" value="90" max="100">90%</progress>
上述解决方案不适用于Firefox!
以下是整体解决方案:
.progress-wrapper {
position: relative;
}
.progress-value {
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
font-size: calc(1rem / 1.5);
line-height: 1rem;
font-weight: bold;
}
.progress.is-small+.progress-value {
font-size: calc(0.75rem / 1.5);
line-height: 0.75rem;
}
.progress.is-medium+.progress-value {
font-size: calc(1.25rem / 1.5);
line-height: 1.25rem;
}
.progress.is-large+.progress-value {
font-size: calc(1.5rem / 1.5);
line-height: 1.5rem;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css" rel="stylesheet" />
<div class="progress-wrapper">
<progress class="progress is-danger is-small" value="90" max="100">90%</progress>
<p class="progress-value has-text-white">90%</p>
</div>
<div class="progress-wrapper">
<progress class="progress is-danger" value="90" max="100">90%</progress>
<p class="progress-value has-text-white">90%</p>
</div>
<div class="progress-wrapper">
<progress class="progress is-danger is-medium" value="90" max="100">90%</progress>
<p class="progress-value has-text-white">90%</p>
</div>
<div class="progress-wrapper">
<progress class="progress is-danger is-large" value="90" max="100">90%</progress>
<p class="progress-value has-text-white">90%</p>
</div>