如何从数据标签中获取文本以出现在进度条上方而不是内部的文字?

发布于 2025-02-12 15:35:45 字数 1042 浏览 2 评论 0原文

我希望这个栏在上面显示文本。我一直在寻找几个小时,决定离开它,然后我想为什么不问这里,是否有人可以给我一些很棒的见解,谢谢!

.exp_bar_container{
  width:100%;
  top: 12em;
  position: relative;
  display:flex;

}


.ExpBar {
  height: 0.5em;
  width: 100%;
  background-color: #dcdcdc;
  position: relative;
  font-weight:bold;
  float: left;

}
.ExpBar:before {
  content: attr(data-label);
  font-size: 0.8em;
  position: absolute;
  text-align: center;
  left: 0;
  right: 0;
}
.ExpBar .value {
  background-color: #323334;
  display: inline-block;
  height: 100%;
}


.ExpBar::-moz-progress-bar {
  background: #dcdcdc;
}

.ExpBar::-webkit-progress-value {
  background: #630862;
}

.ExpBar::-webkit-progress-bar {
  background: #dcdcdc;
}
    <div class="exp_bar_container">
      <progress id="ExpBarId" class="ExpBar" data-label='20/20' value="1" max="100">

      </progress>
    </div>

I would like this bar to have the text appear above it. I have been searching for a couple hours, decided to just leave it and then i thought why not ask here, if anyone could give me some insight on this that would be great, thanks!

.exp_bar_container{
  width:100%;
  top: 12em;
  position: relative;
  display:flex;

}


.ExpBar {
  height: 0.5em;
  width: 100%;
  background-color: #dcdcdc;
  position: relative;
  font-weight:bold;
  float: left;

}
.ExpBar:before {
  content: attr(data-label);
  font-size: 0.8em;
  position: absolute;
  text-align: center;
  left: 0;
  right: 0;
}
.ExpBar .value {
  background-color: #323334;
  display: inline-block;
  height: 100%;
}


.ExpBar::-moz-progress-bar {
  background: #dcdcdc;
}

.ExpBar::-webkit-progress-value {
  background: #630862;
}

.ExpBar::-webkit-progress-bar {
  background: #dcdcdc;
}
    <div class="exp_bar_container">
      <progress id="ExpBarId" class="ExpBar" data-label='20/20' value="1" max="100">

      </progress>
    </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年 2025-02-19 15:35:46

只需添加top:-1em; to .expbar:之前:

.exp_bar_container{
  width:100%;
  top: 12em;
  position: relative;
  display:flex;

}


.ExpBar {
  height: 0.5em;
  width: 100%;
  background-color: #dcdcdc;
  position: relative;
  font-weight:bold;
  float: left;

}
.ExpBar:before {
  content: attr(data-label);
  font-size: 0.8em;
  position: absolute;
  text-align: center;
  left: 0;
  right: 0;
  top: -1em; /* added */
}
.ExpBar .value {
  background-color: #323334;
  display: inline-block;
  height: 100%;
}


.ExpBar::-moz-progress-bar {
  background: #dcdcdc;
}

.ExpBar::-webkit-progress-value {
  background: #630862;
}

.ExpBar::-webkit-progress-bar {
  background: #dcdcdc;
}
<div class="exp_bar_container">
      <progress id="ExpBarId" class="ExpBar" data-label='20/20' value="1" max="100">

      </progress>
    </div>

Just add top: -1em; to .ExpBar:before:

.exp_bar_container{
  width:100%;
  top: 12em;
  position: relative;
  display:flex;

}


.ExpBar {
  height: 0.5em;
  width: 100%;
  background-color: #dcdcdc;
  position: relative;
  font-weight:bold;
  float: left;

}
.ExpBar:before {
  content: attr(data-label);
  font-size: 0.8em;
  position: absolute;
  text-align: center;
  left: 0;
  right: 0;
  top: -1em; /* added */
}
.ExpBar .value {
  background-color: #323334;
  display: inline-block;
  height: 100%;
}


.ExpBar::-moz-progress-bar {
  background: #dcdcdc;
}

.ExpBar::-webkit-progress-value {
  background: #630862;
}

.ExpBar::-webkit-progress-bar {
  background: #dcdcdc;
}
<div class="exp_bar_container">
      <progress id="ExpBarId" class="ExpBar" data-label='20/20' value="1" max="100">

      </progress>
    </div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文