background image wont display

Discussion in 'CSS' started by merwyn, Feb 20, 2012.

  1. #1
    Hi

    I am a newbie with basic understanding of css and html, but i just cant understand why the background image wont display. i tried different images (gif,png,jpeg) etc.

    I have tried by keeping image in same folder as css stylesheet, by keeping image in images folder and giving proper the proper path for example 'images/image.gif' , but nothing works...

    Have attached html code, css (style.txt 'please note it is txt extension only because i was not allowed to upload it as css' , my local copy is style.css) and image.

    Please point out as to where i am making the mistake.

    Thanks in advance
     

    Attached Files:

    merwyn, Feb 20, 2012 IP
  2. themetribe

    themetribe Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    do you have this online? if you have you can put the link so that we can just fix it with firebug.
     
    themetribe, Feb 20, 2012 IP
  3. merwyn

    merwyn Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no i dont have it online :(.... but i have uploaded the concerned files....
    (i have noticed tht the image i hv uploaded is not the same one used in the css file... it should be.... background-image:url(image.gif) no-repeat; )
     
    merwyn, Feb 20, 2012 IP
  4. wiicker95

    wiicker95 Well-Known Member

    Messages:
    438
    Likes Received:
    37
    Best Answers:
    10
    Trophy Points:
    100
    #4
    This is one HUGE error in your css :

    background-image:url('lion.jpeg') no-repeat;

    - You cannot apply the "no-repeat" property if you've put background-image before. This is the primary cause of the error.

    Valid format :
    background: url(lion.jpeg) no-repeat;
    or
    background-image: url(lion.jpeg);
    background-repeat: no-repeat;

    As you can see, I didn't put the apostrophes (" ' "). You shouldn't put them either.

    Hope it helps!
     
    wiicker95, Feb 20, 2012 IP
  5. merwyn

    merwyn Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hi wiicker95

    thanks for the tip, but the image is still not displaying.

    m still stuck.... :(

    i have made the image in photoshop... has it something to do with it ????
     
    merwyn, Feb 20, 2012 IP
  6. merwyn

    merwyn Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i have made a simple 'gif ' image in ms paint but it still does not work............
     
    merwyn, Feb 20, 2012 IP
  7. cosx

    cosx Active Member

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    63
    #7
    First test with the css in header and image in same directory as the html file and then go from there.
     
    cosx, Feb 20, 2012 IP
  8. merwyn

    merwyn Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    hi

    thanks cosx... it works if i keep image and html in same folder.... but it fails if i keep image in different folder say 'images' and i give path in css as 'images/image.gif'....
    can u please tell me why ????
     
    merwyn, Feb 21, 2012 IP
  9. wiicker95

    wiicker95 Well-Known Member

    Messages:
    438
    Likes Received:
    37
    Best Answers:
    10
    Trophy Points:
    100
    #9
    try to put ".../images/image.gif" instead.
     
    wiicker95, Feb 21, 2012 IP
  10. merwyn

    merwyn Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    it did not work :(
    i put 3 dots...
    does it have to be ... (3 dots) before /images/image.gif
    is apostrophe needed ??
     
    merwyn, Feb 21, 2012 IP
  11. wiicker95

    wiicker95 Well-Known Member

    Messages:
    438
    Likes Received:
    37
    Best Answers:
    10
    Trophy Points:
    100
    #11
    In this case it's a quotation mark, and no, you musn't put it. Dots won't work either... :/ What I can suggest is rewriting the whole thing, your CSS is invalid to begin with.
     
    wiicker95, Feb 21, 2012 IP
  12. cosx

    cosx Active Member

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    63
    #12
    Did you managed to figure it out? You should l look up relative paths on gogle and also check w3schools.com for each and every css styling line. My advice, if you are just learning things, keep directory structure simple:

    /index.html => <LINK REL=StyleSheet HREF="css/style.css" TYPE="text/css">
    /css/style.css => background:#fff url(images/image.jpg) no-repeat;
    /images/image.jpg
     
    Last edited: Feb 21, 2012
    cosx, Feb 21, 2012 IP
  13. merwyn

    merwyn Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    hi

    thanks for the tip...
    but it is not working.. i did all of the above... but "image.jpg" from a folder "images" does not display....
    if image is kept in same folder as html then only it works...
    so frustrated... error is likely to be simple.. just cant figure it out... :(
     
    merwyn, Feb 23, 2012 IP
  14. wiicker95

    wiicker95 Well-Known Member

    Messages:
    438
    Likes Received:
    37
    Best Answers:
    10
    Trophy Points:
    100
    #14
    And if you put the whole URL???
     
    wiicker95, Feb 23, 2012 IP