外联css样式表中应该如何 写background-image: url()中的图片路径呢 ? 这里我对相对路径不是很明白。把一

如题所述

相对路径就是指由这个文件所在的路径引起的跟其它文件(或文件夹)的路径关系。

1 两个文件在同一个文件夹下,直接写文件名即可
假设info.html路径是:c:\Inetpub\wwwroot\sites\blabla\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\blabla\index.html
在info.html加入index.html超链接的href应该这样写:index.html

2 要引用的文件在下一级文件夹下,文件名前加子文件夹名称
假设info.html路径是:c:\Inetpub\wwwroot\sites\blabla\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\blabla\html\tutorials\index.html
在info.html加入index.html超链接的href应该这样写:html/tutorials/index.html

3 要引用的文件在上一级文件夹下,文件名前加../
假设info.html路径是:c:\Inetpub\wwwroot\sites\blabla\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\index.html
在info.html加入index.html超链接的代码应该这样写:<a href="../index.html">index.html</a>

举一反三: ../表示源文件所在目录的上一级目录,../../表示源文件所在目录的上上级目录,以此类推。

4 更复杂的情况:
假设info.html路径是:c:\Inetpub\wwwroot\sites\blabla\info.html
假设index.html路径是:c:\Inetpub\wwwroot\sites\html\index.html
在info.html加入index.html超链接的代码应该这样写:<a href="../html/index.html">index.html</a>

css的例子:
如果:网页文件夹下有3.gif和themes文件夹;
themes文件夹下有css文件、1.gif和images文件夹;
images文件夹下有2.gif
那么CSS文件中可以写:
background:url(images/2.gif);
background:url(1.gif);
background:url(../3.gif);

我自己喜欢用dreamweaver,点了url以后在对话框中选图片,免得写错。。

参考资料:http://baike.baidu.com/view/25307.htm

温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-20
形象一点说相对路径就是相对于你保存网页的那个文件夹的路径,..表示根目录,就是你保存网页的那个文档夹。一般图片都会在该文件夹下新建一个文件img或者是images,然后相对路径就该是img/xxx.jpg了,我一般都这么写background:url(../images/logo.gif) no-repeat 0 0;本回答被网友采纳
第2个回答  2010-12-20
/images/i.gif

这是返回跟目录 找images/i.gif