Mar*_*ins 4 html css wordpress
我想添加一个图像作为标题的背景,事情是我不想添加绝对路径,因为我在我的电脑上这样做,他们是上传到我的服务器.
应该<?php bloginfo('template_directory'); ?>在css工作吗?它在这里不起作用.
码:
#branding {
background: url("<?php bloginfo('template_directory'); ?>/images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
Run Code Online (Sandbox Code Playgroud)
dev*_*aly 13
不,你不能在CSS文件中使用PHP.
您仍然可以使用相对路径.如果您的CSS文件和images目录位于同一目录中,则此示例将起作用.WordPress知道这是相对于主题.
#branding {
background: url("images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
Run Code Online (Sandbox Code Playgroud)
如果images目录位于CSS文件的父目录中:
#branding {
background: url("../images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
Run Code Online (Sandbox Code Playgroud)