[英]Is it ok to use <style> tags inside php?
If I have certain styles that need to take place upon some php condition, is it valid and good practice to use the style tag inside php scripts ? 如果我有某些需要在某些php条件下进行的样式,那么在php脚本中使用样式标签是否有效且是一种好习惯?
if(condition){
echo "<style> .div{display:block} </style>";
} else {
echo "<style> .div{display:none} </style>";
}
I am thinking that since the tag is not place in the head of the document, it could be a problem ? 我在想,既然标签没有放在文档的开头,可能是一个问题吗? Or is this a usual way of doing this sort of thing ?
还是这是做这种事情的通常方式?
Thank you. 谢谢。
The way you are doing certainly works, but it's not a good practice to mix PHP with html/css this way. 您的工作方式当然可以,但是以这种方式将PHP与html / css混合并不是一个好习惯。 The best way is to use a template class to manipulate the html.
最好的方法是使用模板类来操作html。
As a beginner you may be overwhelmed with the features of most advanced template classes, so I recommend start with something simple to get the basic concept. 作为一个初学者,您可能不熟悉大多数高级模板类的功能,因此,我建议从简单的入门入手,以获取基本概念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.