【发布时间】:2016-06-28 16:26:06
【问题描述】:
我有两个从数组中获取的值:
$target = $data->data[2][32][3];
在这种情况下$target = 9.83%。
$clicks = $data->data[1][32][3];
在这种情况下$clicks = 7.15%。
我有一个条形图,由.outer div(代表背景 div,包含所有其他元素的 div)、.inner div(填充外部......你可以把它想象成一个显示完成百分比)和.target div(表示虚线/ .inner div 必须达到的目标。在某些情况下,例如它超过了目标:.inner > .target)。
$target = 9.83%;
$bar_width = '200px';
$clicks = 7.15%;
$base = max($target, $clicks);
.outer,
.inner,
.target {
height: 14px;
margin-bottom: 5px;
}
.outer {
background-color: #cccccc;
width: 200px;
margin: 20px auto;
position: relative;
font-size: 10px;
line-height: 14px;
font-family: sans-serif;
}
.inner {
background-color: green;
position: absolute;
z-index: 1;
text-align: right;
width: calc(200 / 100 * <?php echo $base; ?>);
border-right: 2px solid black;
}
.inner:after {
content: ' 7.15%';
display: inline-block;
left: 10px;
position: relative;
height: 100%;
top: -14px;
margin-left: 17px;
}
.target {
background-color: transparent;
width: 19px;
position: absolute;
z-index: 2;
color: black;
text-align: right;
border-right: 2px dotted black;
}
.target:after {
content: 'Target: 9.83%';
display: inline-block;
left: 28px;
position: relative;
height: 100%;
top: 14px;
margin-left: -60px;
}
<div class="outer">
<div class="target" style="width: calc(<?php echo $bar_width; ?> / 100 * (<?php echo $target; ?> / <?php echo $base; ?> * 100))">
</div>
<div class="inner" style=" width: calc(<?php echo $bar_width; ?> / 100 * (<?php echo $clicks; ?> / <?php echo $base; ?> * 100))">
</div>
</div>
所以我的问题是,超过目标后,内部 div 应该完全填满外部 div。
【问题讨论】:
标签: javascript php html css