Oskar Sherrah
Oskar Sherrah

Reputation: 93

How do I put text into a progress bar in HTML5 with bulma?

By default, what you put in between the <progress></progress> tags will not show.

<progress class="progress" value="15" max="100">15%</progress>

How would I get the 15% to show? I am using Bulma as a framework.

Upvotes: 5

Views: 3518

Answers (2)

Temani Afif
Temani Afif

Reputation: 273807

Use pseudo element and data attribute (works only on chrome ...)

.progress:before {
  content:attr(data-text);
}
.progress {
 text-align:center;
}
<progress class="progress" value="15" max="100" data-text="15%"></progress>

Or you can simply consider an extra wrapper:

.progress:before {
  content:attr(data-text);
  position:absolute;
  left:0;
  right:0;
}
.progress {
 text-align:center;
 display:inline-block;
 position:relative;
}
<div class="progress" data-text="15%"><progress  value="15" max="100" ></progress></div>

Including bulma:

.progress-container:before {
  content: attr(data-text);
  position: absolute;
  left: 0;
  right: 0;
  top:0;
  line-height:1em;
}

.progress-container {
  text-align: center;
  position: relative;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css" rel="stylesheet" />
<div class="progress-container" data-text="15%"><progress class="progress" value="15" max="100"></progress></div>

Upvotes: 4

לבני מלכה
לבני מלכה

Reputation: 16251

Wrap you progress with div and add span

(I did not use :after/before and it has to work in all browser)

See fiddle using bulma

<div>
<span>
  15%
</span>
<progress  class="progress" value="15" max="100" >

</progress>
</div>

CSS:

span{
    position: absolute;
    top: -2px;
    left: 50%;
    font-size: 12px;
}

Upvotes: 0

Related Questions