问题
Why when I use progress from Bulma CSS framework (https://bulma.io/documentation/elements/progress/)
and I put text between tags, I don't see any value.
<progress class="progress is-danger" value="90" max="100">90%</progress>
How add text on middle on progress in Bulma?
回答1:
It's normal that you don't see the value
<progress value="90" max="100">90%</progress>
There is no built-in solution.
But according to show-a-progress-bars-value-number-like-55-on-the-bar-by-using-css the following is a solution
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>
UPDATE
The solution above does not work on Firefox!
Here is an overall solution:
.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>
来源:https://stackoverflow.com/questions/50400219/bulma-progress-text-in-middle