CSS 文件中的相对路径是否相对于 CSS 文件? [英] Is a relative path in a CSS file relative to the CSS file?

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

问题描述

当我通过相对路径引用 CSS 文件中的图像或其他文件时,路径是相对于 CSS 文件还是使用 CSS 文件的 HTML 文件?

When I reference an image or other file in a CSS file by a relative path, is the path relative to the CSS file or the HTML file using the CSS file?

推荐答案

是的,它是相对于 .css

这是一个示例布局:

Page:  page.htm ... does not matter where
CSS:   /resources/css/styles.css  
Image: /resources/images/image.jpg

styles.css 中的 CSS:

div { background-image: url('../images/image.jpg');

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

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