0

I'm using bootstrap (imported styles using link so don't have a local css file), and am trying to set image as background for a div. The relative path I'm writing doesn't work. I searched online and everyone says to base the relative path off of css file (but I don't have a css file due to using bootstrap via link). How shall I write my relative path to get to 'banner.jpg'? enter image description here

Ari
  • 153
  • 2
  • 6
  • 1
    I would start from the root .. Not work my way back .. Start from your **base** html directory by starting with `/` IE `url("/from/base/dir/to/static/banner.png")` – Zak Apr 09 '21 at 22:44
  • Just use full url `https://example.com/image.webp` and problem solved. – Jakub Muda Apr 09 '21 at 22:47
  • Yes using a web link works but if my image is not hosted on a website then I have to use relative path... – Ari Apr 11 '21 at 00:42

1 Answers1

0

Relative paths are based off the file in question. If you're not using a CSS file and instead you've got a <style> block in an html file, then make the path relative to that file.

If it's still not showing up, it's likely due to another issue (such as the #banner element not matching or having no explicit width or height).

If you add a minimum reproducible example, the community can be more helpful.

Tim
  • 2,843
  • 13
  • 25