是否可以在存储在php变量中的css3中显示背景图像?
是否可以在存储在php变量中的css3中显示背景图像是否可以在存储在php变量中的css3中显示背景图像?,php,css,Php,Css,是否可以在存储在php变量中的css3中显示背景图像 body{ margin: 0; padding: 0; border: 0; text-decoration: none; background-image: url("$background_img_location"); } 完成查询后,在PHP脚本中生成CSS: ?> <style> body{ margin: 0; padding: 0; borde
body{
margin: 0;
padding: 0;
border: 0;
text-decoration: none;
background-image: url("$background_img_location");
}
完成查询后,在PHP脚本中生成CSS:
?>
<style>
body{
margin: 0;
padding: 0;
border: 0;
text-decoration: none;
background-image: url("<?php echo $background_img_location; ?>");
}
</style>
?>
身体{
保证金:0;
填充:0;
边界:0;
文字装饰:无;
背景图片:url(“”);
}
页面代码中的某个地方
<style type="text/css">
body {
background-image: url("<?php echo $background_img_location; ?>");
}
</style>
身体{
背景图片:url(“”);
}
不要使用.css文件扩展名,而是使用.php
<link rel='stylesheet' type='text/css' href='css/style.php' />
在新style.php文件的顶部,将内容类型设置回CSS:
<?php
header("Content-type: text/css; charset: UTF-8");
?>
为您喜欢的内容设置变量:
<?php
header("Content-type: text/css; charset: UTF-8");
$bgImage = 'http://www.somesite.com/bgimage.jpg';
?>
在所有这些PHP内容下面,您可以添加常规CSS以及一些PHP来输出变量:
body{
margin: 0;
padding: 0;
border: 0;
text-decoration: none;
background-image: url("<?php echo $bgImage; ?>");
}
正文{
保证金:0;
填充:0;
边界:0;
文字装饰:无;
背景图片:url(“”);
}
最终输出应如下所示:
<?php
header("Content-type: text/css; charset: UTF-8");
$bgImage = 'http://www.somesite.com/bgimage.jpg';
//declare more variables here
?>
body{
margin: 0;
padding: 0;
border: 0;
text-decoration: none;
background-image: url("<?php echo $bgImage; ?>");
}
/* more css here */
身体{
保证金:0;
填充:0;
边界:0;
文字装饰:无;
背景图片:url(“”);
}
/*更多的css在这里*/
以纯文本而不是图像的形式发布代码。太棒了!很高兴我能帮忙=D