I am building a website using "build your own website the right way using HTML & CSS (3rd ed) by Ian Lloyd. Brilliant book but I can't get a background image onto my header or my navigation plane. I would like to use a photograph I have stored on my computer but the intructions in the book only refer to "url" sourced images. Can anyone help?
The image needs to be in a location relative to where you have the web page. If you set up a folder called images and save the background image there as myphoto.jpg then the entry for the CSS would be url('images/myphoto.jpg')
Yes, and that works whether the site is just sitting on your own computer or has been uploaded to the web.
As felgall said, it's all a question of where the image is in relation to the CSS file requesting it. So, let's say your main root folder contains a file called styles.css and an /images/ folder with the myphoto.jpg image in it. In that circumstance, you would use the link that felgall gave, i.e.
But if you styles.css file is inside a /css/ folder itself, that link won't work. The link would then be
The dots at the start mean 'go up one folder first'. So this assumes that the /css/ folder is in the main root folder, as the /images/ folder is.
Once you have this all set up, you can just double click on your web page file (e.g. index.html) and it will open in your browser. What you see in your browser is still a URL, even though it's just a messy looking location on your own computer.
Many thanks you guys. I'll try that out
This topic is now closed. New replies are no longer allowed.