使用php隐藏div [英] Hiding a Div using php
问题描述
我目前隐藏一个基于if语句的div。我使用的方法是通过回显css风格的显示:无
I am currently hiding a div based on a if statement. The method I use is by echo-ing out a css style of "display: none"
这里是我正在做的具体:
Here is what I am doing specifically:
<style>
#content{
<?php
if(condition){
echo 'display:none';
}
?>
}
</style>
<body>
<div id="content">
Foo bar
</div>
</body>
我的问题是;这是隐藏div的好方法吗?没有浏览器,缓存样式,因此忽略回声输出css样式?
My question is; Is this a good method of hiding a div? Wont a browser, cache the style and therefore ignore the echo-ed out css style?
谢谢,
Vidhu
Thanks, Vidhu
推荐答案
在您的CSS中使用Php(级联样式表)不是正确,
Using Php in your CSS (Cascade Style Sheet) is not "proper",
在HTML中使用Php:
Also, You can use Php in your HTML:
<body>
<?php if (condition){ ?>
<div id="content">
Foo bar
</div>
<?php } ?>
</body>
使用此代码,div块不会出现, ),你可以使用它隐藏你的div:
With this code, div block don't appear, (and you don't use it with JavaScript), You can use this for just hidden your div :
<body>
<div id="content" <?php if (condition){ echo 'style="display:none;"'; } ?>>
Foo bar
</div>
</body>
这篇关于使用php隐藏div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!