在div中间显示垂直图形条百分比

时间:2016-07-15 13:51:38

标签: html css

我有一个进度条,我需要能够始终在进度条的中间显示百分比文本。目前,只有值不在进度条内垂直居中。我只需要使用html和CSS而不是jQuery或javascript

enter image description here

<div class="column inline inline-4 center choice" ng-repeat="repeat in repeater">
    <div ng-repeat="value in repeat.keuze_menu[0]">
        <span>{{value.title}}</span>
        <img alt="" src=""/>
    </div>
</div>
.vertical .progress-bar {
  float: left;
  height: 100px;
  width: 40px;
  margin-right: 10px;
}
.vertical .progress-track {
  position: relative;
  width: 40px;
  height: 100%;
  background: #fff;
  border: 1px solid #ebebeb;
}
.vertical .progress-fill {
  position: relative;
  height: 50%;
  width: 40px;
  color: #fff;
  text-align: center;
}

2 个答案:

答案 0 :(得分:0)

以下修改的答案;请参阅此处的小提琴:https://jsfiddle.net/ybygucn7/

HTML:

<div class="vertical">
    <div class="progress-bar">
        <div class="progress-track">
             <span style="color: rgb(0, 0, 0);">100%</span>
             <div class="progress-fill" style="height: 100%; background: rgb(191, 231, 178);"></div>   
        </div>
   </div>
</div>

CSS:

.vertical .progress-bar {
  height: 100px;
  width: 40px;
  display: inline-block;
  margin: 0 5px;
  font-size: 12px;
  text-align: center;
}

.progress-bar .progress-track {
  width: 100%;
  height: 100%;
  background: #fff;
  border: 1px solid #ebebeb;
  position: relative;
}

.vertical .progress-fill {
    width: 100%;
    color: #fff;
    text-align: center;
    position: absolute;
    z-index: 0;
    bottom: 0;
}

.vertical span {
    position: absolute;
    z-index: 1;
    top: 50%;
    width: inherit;
    left: 0;
    transform: translateY(-50%);
}

答案 1 :(得分:0)

我已对您的HTML进行了更改,而在.progress-bar溢出已hidden,请尝试此操作。

&#13;
&#13;
.vertical .progress-bar {
  float: left;
  height: 100px;
  width: 40px;
  margin-right: 10px;
  overflow:hidden;
}
.vertical .progress-track {
  position: relative;
  width: 40px;
  height: 100%;
  background: #fff;
  border: 1px solid #ebebeb;
  //overflow:hidden;
}
.vertical .progress-fill {
  position: relative;
  height: 50%;
  width: 40px;
  color: #fff;
  text-align: center;
}
&#13;
<div class="vertical">
  <div class="progress-bar">
    <div class="progress-track">
      <span style="color: rgb(0, 0, 0);top:20%;position:absolute;z-index:1;">100%</span>
      <div class="progress-fill" style="background: rgb(191, 231, 178);height:100px; top:0%;"></div>
         </div>
  </div>

  <div class="progress-bar">
    <div class="progress-track">
      <span style="color: rgb(0, 0, 0);top:20%;position:absolute;z-index:1;">80%</span>
       <div class="progress-fill" style="background: rgb(248, 231, 153);height:80px; top:20%;"></div>
       </div>
  </div>

  <div class="progress-bar">
    <div class="progress-track">
      <span style="color: rgb(0, 0, 0);top:40%;position:absolute;z-index:1;">60%</span>
   <div class="progress-fill" style="background: rgb(248, 231, 153);height:60px; top:40%;"></div>
   
    </div>
  </div>

  <div class="progress-bar">
    <div class="progress-track">
        <span style="color: rgb(0, 0, 0);top:40%;position:absolute;z-index:1;">0%</span>
<div class="progress-fill" style="background: rgb(248, 138, 138);height:5px; top:95%;">
      </div>

    </div>
  </div>
</div>
&#13;
&#13;
&#13;