Hello, I am currently working on the Dasmoto Arts & Crafts project and am having trouble linking an image file on my CSS stylesheet to use as a background image for my h1 heading. I currently have the pattern.jpeg saved in a folder called “images” that is located within a folder called “resources”, which is located within my project folder called “Dasmoto”. (None of the folder names include the quotations, those are just in this post for clarity.) Below is a copy of the HTML and CSS that I have so far:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dasmoto Arts & Crafts</title>
<link rel="stylesheet" href="./resources/css/index.css">
<h1> Dasmoto's Arts & Crafts </h1>
background-image: url ("/resources/images/pattern.jpeg" );
With the code as it is written above, my h1 text shows as expected with a dark gray color background, but no matter what I try, I can’t get the image to show up.
Can anyone help me understand how to create a proper path for a background image? Thank you!
Where is your css file? Is that also located in the folder ‘Dasmoto’? Or in a subfolder?
Try changing “/resources/images/pattern.jpeg” to “./resources/images/pattern.jpeg”
. in front of /resources
Yes, my css file called index.css is in a folder called “css” which is in my “resources” folder within the Dasmoto folder. Is it too many folders deep? I was just trying to be organized.
I have tried putting the . in front of /resources but that didn’t seem to change anything when I refreshed the webpage.
Then the path
/resources/images/pattern.jpeg starts in your css folder. You need to move out of that folder first. You do that with two dots:
url ("../resources/images/pattern.jpeg" );
Then this relative path starts in your root folder
Ok, this is what I have now per what I understood from your suggestion:
background-image: url ("../resources/images/pattern.jpeg");
Then I refreshed the webpage and I am still only seeing my darkgray background color and not the pattern.jpeg image. I must be doing something else wrong because what you said made total sense.
Ok I think I understand your folder structure
Have you checked the debugging tool? That tells you where it is searching the file if it fails to do so.
Your current code requires the following file structure:
root folder (Dasmoto → better use lower case for folder names)
I guess I don’t know how to use the debugging tool. There has not been a codecademy exercise related to this. I will change the folder name of Dasmoto to dasmoto though just for consistency.
Try Chrome browser and rightclick on your headline. Then in the context menu ‘inspect’ (or a similar term → mine shows the german terms). Then a side bar should open with your html tree and a console that shows errors in your code.
Can you post a screenshot of your file structure?
So your css folder and the images folder are in the folder
resources is not part of the relative path and you just need to move out of the css folder with the two dots:
I tried that, and it still didn’t change anything. Here is a screen shot of the Chrome DevTools with my header section highlighted. You can see where it says background-image that the whole line of code is crossed out. Not sure what to do from here.
See how the line
background-image is crossed out in the debugging tool?
Try to remove that space between url and the opening parenthesis.
That was it! It finally worked!! Thank you for working me through this because it was unendingly frustrating!