wordpress 3.3 CSS中的相对路径 [英] wordpress 3.3 relative paths in CSS

查看:136
本文介绍了wordpress 3.3 CSS中的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个图像作为标题的背景,事情是,我不想添加一个绝对路径,因为我这样做在我的电脑,他们是上传到我的服务器。 / p>

应该<?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;
}

如果images目录在CSS文件的父目录中:

  #branding {
background:url(../ images / background2.jpg)repeat-x repeat-y;
height:150px;
}


I want to add an image to be a background of the header, the thing is that I don't want to add an absolute path since I'm doing this on my pc and them is to upload to my server.

should the <?php bloginfo('template_directory'); ?> work in the css? It is not working here.

code:

#branding {
    background: url("<?php bloginfo('template_directory'); ?>/images/background2.jpg") repeat-x repeat-y;
    height: 150px;
}

解决方案

No, you can't use PHP within a CSS file.

You can still use a relative path. This example will work if your CSS file and images directory are in the same directory. WordPress knows this is relative to the theme.

#branding {
    background: url("images/background2.jpg") repeat-x repeat-y;
    height: 150px;
}

If the images directory is in a parent of the CSS file:

#branding {
    background: url("../images/background2.jpg") repeat-x repeat-y;
    height: 150px;
}

这篇关于wordpress 3.3 CSS中的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆