可以使用变量动态选择css中的宽度

时间:2012-07-07 09:31:46

标签: php html css

代码是:

<div class="bar">
    <div class="percentage" style="width:16%; height: 59px;">This is 66% wide div</div>
</div>

正如你在这里看到的宽度是16 ......我需要一种方法,它可以根据变量来改变。我有一个PHP查询返回一个特定的值。宽度必须是那个谷。我怎么能这样做?

1 个答案:

答案 0 :(得分:4)

你可以用Javascript来做。例如,使用JQuery:

$('.percentage').css({'width': x%, 'height': xpx});

或者你可以用PHP做到这一点:

<div class="percentage" style="width: <?php echo $width; ?>%; height: <?php echo $height; ?>px; ">This is 66% wide div</div>
相关问题