为 css 指定基本 url [英] Specifying base url for css

查看:21
本文介绍了为 css 指定基本 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不拆分一个很长的 css 文件.我将较小的 css 文件放在 styles 目录中.

I had to split up a long css file. I put the smaller css files within a styles directory.

现在我必须更新网址以使用 ../ 符号上升一级.

Now I have to update the the urls to go up one level with the ../ notation.

无论如何要指定从其加载资产的基本 URL,例如 HTML 中的 base 标记,但使用 CSS?

Is there anyway to specify the base URL from which to load assets like with the base tag in HTML, but with CSS?

推荐答案

不,没有.我建议将 CSS 图像至少放置在与 CSS 文件相同的级别,这样您就不需要在路径中倒退.例如./css 文件夹用于 CSS 文件,/css/images 文件夹用于 CSS 图像.然后你可以一致地使用 url('images/name.ext') 来处理 CSS 图像.通过这种方式,您几乎可以将根 /css 文件夹放在几乎任何地方,而无需摆弄图像 URL.

No, there isn't. I suggest to place the CSS images in at least the same level as the CSS file so that you don't need to go backwards in the path. E.g. /css folder for CSS files and /css/images folder for CSS images. Then you can consistently use url('images/name.ext') for CSS images. This way you can place the root /css folder practically everywhere without fiddling with the image URL's.

这篇关于为 css 指定基本 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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