SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Using background images

    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?

    Vince

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,813
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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')
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,177
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by Vince2011 View Post
    the intructions in the book only refer to "url" sourced images.
    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.

    Code:
    background: url('images/myphoto.jpg');
    But if you styles.css file is inside a /css/ folder itself, that link won't work. The link would then be

    Code:
    background: url('../images/myphoto.jpg');
    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.

  4. #4
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks you guys. I'll try that out


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •