Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于PHP变量值的元素宽度%_Php_Html_Css - Fatal编程技术网

基于PHP变量值的元素宽度%

基于PHP变量值的元素宽度%,php,html,css,Php,Html,Css,考虑以下几点: $a=25; $b=75; <div id='container'> <div id='a'></div> <div id='b'></div> </div> #container{ width: 100% } #a{ Width: $a //here I need to get the value of $a } 我想显示一个基于$a和$b值的百分比条。我想用div表示百分比条 我想我需

考虑以下几点:

$a=25;
$b=75;
<div id='container'>
  <div id='a'></div>
    <div id='b'></div>
</div>

#container{
width: 100%
}

#a{
Width: $a //here I need to get the value of $a
}
我想显示一个基于
$a
$b
值的百分比条。我想用div表示百分比条

我想我需要做以下几点:

$a=25;
$b=75;
<div id='container'>
  <div id='a'></div>
    <div id='b'></div>
</div>

#container{
width: 100%
}

#a{
Width: $a //here I need to get the value of $a
}

#容器{
宽度:100%
}
#a{
宽度:$a//这里我需要得到$a的值
}
你知道我该怎么做吗

我需要在
外部样式表
中得到这个

我希望实现的目标是,记住a美元和b美元的价值是不同的


动态构建(并保存)CSS文件时,只能在CSS文件中使用PHP变量。如果值经常更改(例如,它取决于页面或内容),我不建议这样做。相反,您可以完美地使用内联样式块:

<style> #a { width: <php echo $a; ?>; } </style>

动态构建(并保存)CSS文件时,只能在其中使用PHP变量。如果值经常更改(例如,它取决于页面或内容),我不建议这样做。相反,您可以完美地使用内联样式块:

<style> #a { width: <php echo $a; ?>; } </style>

^这是内联css还是外部css文件?它应该是外部的!!您应该在问题中提到这一点。在外部css文件中添加php是不可能的,但是您可以使用javascript@sgtBOSE对不起,我忘了提到我会投票支持你的答案…但是现在你删除了它^这是内联css还是应该是外部css文件?应该是外部的!!您应该在问题中提到这一点。在外部css文件中添加php是不可能的,但是您可以使用javascript@sgtBOSE很抱歉,我忘了提到我会投票支持你的答案…但是现在你删除了我的问题这就是我所做的:
if($count>0){echo';}else{echo';
但是现在我如何确保条的总和始终为100%,因为$t1变化,而不是超过100确定这就是我所做的:
如果($count>0){echo';}否则{echo';
但是现在我如何确保条的总和始终为100%,因为$t1变化,而不是超过100