Specifying base url for css

2019-01-18 08:02发布

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.

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

标签: html css url path
2条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-18 08:36

As an alternative, you could dynamically add a class to your body tag, and use that in selectors to override css URLs depending on which directory your file is served from.

查看更多
欢心
3楼-- · 2019-01-18 08:57

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.

查看更多
登录 后发表回答