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

前端 未结 8 2288
名媛妹妹
名媛妹妹 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 03:58

    It's relative to the stylesheet, but I'd recommend making the URLs relative to your URL:

    div#header { 
      background-image: url(/images/header-background.jpg);
    }
    

    That way, you can move your files around without needing to refactor them in the future.

提交回复
热议问题