how does the path work in css and js

前端 未结 4 1610
滥情空心
滥情空心 2021-01-25 08:30

These days I meet so many problems about the path in css and js. And after a few tests,I can not have a exact answer,so i ask here for help.

1 The

4条回答
  •  抹茶落季
    2021-01-25 08:55

    The path is always relative to the path the file referring to it is in. So, let's say your css is in /css/mystyel.css and images are in the path /img, then you refer to that image in css with:

    background-image:url(../img/myimg.jpg)
    

    If your js in in /js/myscript.js and you are adressing it from a html-file like /somepath/somehtml.html, then you use:

    
    

    If the html was in /somepath/somotherpath/somehtml.html, you would have used src="../../js/myscript.js"

提交回复
热议问题