是否可以在存储在php变量中的css3中显示背景图像?
body{
margin: 0;
padding: 0;
border: 0;
text-decoration: none;
background-image: url("$background_img_location");
}
答案 0 :(得分:0)
执行查询后,在PHP脚本中生成CSS:
?>
<style>
body{
margin: 0;
padding: 0;
border: 0;
text-decoration: none;
background-image: url("<?php echo $background_img_location; ?>");
}
</style>
答案 1 :(得分:0)
您网页代码中的某处...
<style type="text/css">
body {
background-image: url("<?php echo $background_img_location; ?>");
}
</style>
答案 2 :(得分:0)
请使用.php
,而不要使用.css文件扩展名<link rel='stylesheet' type='text/css' href='css/style.php' />
在新style.php文件的顶部,将Content-type设置回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; ?>");
}
最终输出应如下所示:
<?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 */