我有两个div,代表两条线(虚线和实线),通过php获取了两个数字。我需要将这些数字放在那些线的上方和下方,就像这样:
CSS:
.outer, .inner, .target {
height: 14px;
margin-bottom: 5px;
}
.outer {
background-color: #cccccc;
width: 80%;
margin: 0 auto;
position: relative;
font-size: 10px;
line-height: 14px;
font-family: sans-serif;
}
.inner {
background-color: <?php echo $color?>;
position: absolute;
z-index: 1;
color: white;
}
.target {
background-color: transparent;
width: 19px;
position: absolute;
border-right: 2px dotted black;
z-index: 2;
color: black;
text-align: right;
}
.solid_line{
color: black;
float: right;
width: 3px;
border-right: 3px solid black;
height: 16px;
}
<div class="outer">
<div class="target" style="width: calc(<?php echo $bar_width; ?> / 100 * (<?php echo $target; ?> / <?php echo $base; ?> * 100))">
<div>Target: <?php echo number_format((float)$target, 2, '.', ''); ?>%
</div>
</div>
<div class="inner" style=" width: calc(<?php echo $bar_width; ?> / 100 * (<?php echo $avg; ?> / <?php echo $base; ?> * 100))">
<div class="solid_line">
<div><?php echo number_format((float)$avg, 2, '.', ''); ?>%</div>
</div>
</div>
</div>
现在它看起来像这样:
left: ??px
,然后使用jQuery覆盖左侧数字,这样它就会随着数字的变化而改变。 - Andrew