Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling an image from CSS

Tags:

html

css

image

  • My .html files are all in Assignment1/*.html files
  • My CSS file is in Assignment1/style/cssfile.css
  • My images are in Assignment1/images/images.png

How do i call an image from Assignment1/style/cssfile.css to Assignment1/images/images.png file?

I can`t do it like the html files as i could just forward the folders to go through. I am trying to do:

.top {background-image: url("Assignment1/images/deco1400.png");}

from the css file to no avail.

How can I reference my image files from my CSS that are in different directories.

like image 287
Anthony Do Avatar asked Nov 29 '25 16:11

Anthony Do


1 Answers

try

background-image: url("../images/deco1400.png");

Your tree structure is like

Assignment1
  style
    style.css <- you are here
  images
    img1.png

so either you need to go 1 level up (..) and then enter images OR you need to give absolute path /images/img1.png (note / at the beginning). Both should work, assuming Assignment is your root directory

UPDATE: you might be interested in reading about relative and absolute paths.

like image 169
mkk Avatar answered Dec 02 '25 07:12

mkk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!