Relative paths of images in JavaScript

前端 未结 3 2115
我在风中等你
我在风中等你 2021-02-18 23:11

I have a javascript module which creates a div with a picture of a close button (\"X\"). This div and javascript are placed in many places on my site.

Relative path solu

3条回答
  •  一个人的身影
    2021-02-18 23:28

    Can't you just use a CSS class? If it's just a div containing an img, you can get rid of the img and use background-image on the div. Setting this from CSS will make sure that the image path is always relative to the CSS file and will almost certainly work no matter the environment (as long as the other images in your CSS work).

    Then, you can just set the className on your div accordingly.

提交回复
热议问题