如何在css中使用相对路径?
在我的wordpress网站上,我目前在css中有以下url: 图像存储在以下位置:如何在css中使用相对路径?,css,wordpress,image,url,Css,Wordpress,Image,Url,在我的wordpress网站上,我目前在css中有以下url: 图像存储在以下位置: http://localhost/sigma/wp-content/uploads/2016/10/iconsigma.png 我的css文件在 wp-content/themes/sigma 我尝试了以下方法,但似乎不起作用&我不知道为什么: background-image: url('../../wp-content/uploads/2016/10/iconsigma.png') no-repeat;
http://localhost/sigma/wp-content/uploads/2016/10/iconsigma.png
我的css文件在
wp-content/themes/sigma
我尝试了以下方法,但似乎不起作用&我不知道为什么:
background-image: url('../../wp-content/uploads/2016/10/iconsigma.png') no-repeat;
请问有人能提供指导吗 使用from style.css (使用相对路径) 或(使用绝对路径) 或者,如果您可以将图像移动到主题的img文件夹中,然后使用(在style.css中),则效果更好 如果要从php文件调用背景图像:
background-image: url('<?php echo trailingslashit( get_template_directory_uri() ); ?>img/iconsigma.png') no-repeat;
背景图片:url('img/iconsigma.png')不重复;
这是您的目录
wp-content > themes > sigma
- 您正处于
sigma
=>。/
/themes/
=>。/
/wp content/
/wp content/uploads/2016/10/iconsigma.png
添加到路径中
因此,您正在/wp content/wp content/uploads/2016/10/iconsigma.png
解决方案
您必须将
。/../wp content/uploads/2016/10/iconsigma.png
更改为。/../uploads/2016/10/iconsigma.png
url应该是这样的
background-image: url('/sigma/wp-content/uploads/2016/10/iconsigma.png') no-repeat;
从相对路径中删除
/wp content
。
background-image: url('<?php echo trailingslashit( get_template_directory_uri() ); ?>img/iconsigma.png') no-repeat;
wp-content > themes > sigma
background-image: url('/sigma/wp-content/uploads/2016/10/iconsigma.png') no-repeat;