I am having trouble displaying a background image on a web page and have no clue what’s wrong. I am sure it’s something simple that I just don’t see. Here is the code:
css #header{
/works/
background-color: yellow;
/does not work/
background-image: url(‘…/pictures/solidgreen.jpg’);
/moved jpg to root directory. does not work/
background-image: url(‘solidgreen.jpg’);
}
index.html
<div id=“header”>
<p>This text displays in the header</p>;
</div>
The solidgreen.jpg file is a test file I created thinking there might be something wrong with the jpg file I am trying to display. Nothing works.
Thanks for any suggestions or help with this simple, perplexing problem.
That’s no use unless the css file is in the root folder too. Looks like a file path problem. Where is the css file in relation to the image? (That is, what’s your file structure?) We could check for you if you post a link.
I am developing the site on my computer and don’t have a link you can see. The css folder and pictures folder are both in the root directory. What I have is:
Mywebsie
index.html
css folder
pictures folder
I believe it is a path problem, also, but I can’t see what it is.
Thank you.
A friend suggested I zip the directory on my computer and post it. You could see the whole website. It is not a large site at this point. Would that be helpful?
This is EXACTLY why my directory structure ALWAYS points down-tree… if you have to root or uptree (…/) it over something simple like a image link, you probably have your file structure needlessly convoluted. Images for CSS should be in a subdirectory of wherever the CSS is – since they are inherently (or should be) presentational that also makes reskinning easier as you can swap out CSS images and the CSS (theme) without effecting the content.
SERIOUSLY, if you have to start a URL in your CSS with “/” or “…/” there is probably something horribly wrong with your directory structure.
I have finally solved the problem. As all of you have suggested, it was a syntax issue. Thanks to all who gave me suggestions. I tried them all until I hit paydirt.