Using relative URL in CSS file, what location is it relative to?

前端 未结 8 2267
名媛妹妹
名媛妹妹 2020-11-22 03:29

When defining something like a background image URL in a CSS file, when using a relative URL, where is it relative to? For example:

Suppose the file /styleshe

8条回答
  •  隐瞒了意图╮
    2020-11-22 04:10

    One issue that can occur, and seemingly break this is when using auto minimization of css. The request path for the minified bundle can have a different path than the original css. This may happen automatically so it can cause confusion.

    The mapped request path for the minified bundle should be "/originalcssfolder/minifiedbundlename" not just "minifiedbundlename".

    In other words, name your bundles to have same path (with the /) as the original folder structure, this way any external resources like fonts, images will map to correct URIs by the browser. The alternative is to use absolute url( refs in your css but that isn't usually desirable.

提交回复
热议问题