![](/img/trans.png)
[英]Can we make an image dynamic in WordPress that is set as background in Style.css?
[英]With Wordpress, how do I link to an image to use as a background in my style.css file?
我知道在HTML / PHP文件中我可以做类似的事情
<img src="<?php bloginfo('template_url'); ?>/path/to/image.png" />
但是在CSS中,如果我想这样做,显然我不能这样做
background: url('<?php bloginfo('template_url') ?>/images/linen.png');
即使我想要
我将如何实现类似的效果?
您不应该使用<?php bloginfo('template_url'); ?>
<?php bloginfo('template_url'); ?>
在CSS文件中。 CSS文件中的URL相对于当前CSS文件。
因此,如果您具有以下目录结构
theme/
images/
linen.png
css/
styles.css
您的CSS规则看起来像
background: url('../images/linen.png');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.