我想添加一个图像作为标题的背景,问题是我不想添加绝对路径,因为我在我的电脑上这样做,它们是上传到我的服务器。
应该<?php bloginfo('template_directory'); ?>
在CSS工作?它在这里不起作用。
代码:
#branding {
background: url("<?php bloginfo('template_directory'); ?>/images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
最佳答案
不,您不能在 CSS 文件中使用 PHP。
您仍然可以使用相对路径。如果您的 CSS 文件和图像目录位于同一目录中,则此示例将有效。 WordPress 知道这是与主题相关的。
#branding {
background: url("images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
如果图像目录在 CSS 文件的父目录中:
#branding {
background: url("../images/background2.jpg") repeat-x repeat-y;
height: 150px;
}
关于html - CSS 中的 wordpress 3.3 相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10058167/