加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 另一个文件夹中的CSS图像

发布时间:2020-12-14 18:27:08 所属栏目:资源 来源:网络整理
导读:参见英文答案 Using relative URL in CSS file,what location is it relative to?8个 我将图像添加到名为“images”的文件夹中,将CSS添加到名为“css”的文件夹中,现在我想使用“images”文件夹中的图像.我该怎么做呢?当我使用它时,它们没有出现: backgrou
参见英文答案 > Using relative URL in CSS file,what location is it relative to?8个
我将图像添加到名为“images”的文件夹中,将CSS添加到名为“css”的文件夹中,现在我想使用“images”文件夹中的图像.我该怎么做呢?当我使用它时,它们没有出现:
background: url('/images/bg.jpg');

我也试过这些:

background: url('../images/bg.jpg');
background: url('../../images/bg.jpg');

我应该用什么路径来访问我的图片?

解决方法

如果您有如下文件夹结构:
/public_html/
    /css/
    /images/
    /index.html

然后你的CSS应该工作.

  • Starting with “/” returns to the root directory and starts there
  • Starting with “../” moves one directory backwards and starts there
  • Starting with “../../” moves two directories backwards and starts there (and so on…) To move forward,just start with the first
    subdirectory and keep moving forward

在这里阅读更多:http://css-tricks.com/quick-reminder-about-file-paths/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读