HTML and CSS Background-image is not showing up

后端 未结 5 2037
太阳男子
太阳男子 2021-02-20 12:55

I already double checked my URL, and the name of the files, but I can\'t seem to get the image to show up. Why is it like that? Here\'s my code (take note the

相关标签:
5条回答
  • 2021-02-20 12:57

    I know this answer is a bit late but this link will give you a detailed explanation for css file paths.

    / returns to the root directory
    ../ moves one directory backwards
    ../../ moves two directory backwards
    

    https://css-tricks.com/quick-reminder-about-file-paths/

    0 讨论(0)
  • 2021-02-20 12:59

    The browser will be searching for the image within your stylesheet directory at the moment.

    Might be worth trying changing

    background-image: url(images/background.gif);
    

    to

    background-image: url(/images/background.gif);
    

    which might be the cause of the problem.

    0 讨论(0)
  • 2021-02-20 13:20

    Try this:

    background-image: url(../images/background.gif);
    

    Without the ../ it is looking for an images folder inside your stylesheet folder which does not exist. So you have to go back a directory where the images folder is located.

    Edit: You can also shorten up your CSS styles like so:

    .guarantee{
        background: #a7cece url(../images/background.gif);
        border: 1px solid black;
    }
    
    0 讨论(0)
  • 2021-02-20 13:24

    I was having this same problem solved it by adding / to the beginning of the image url

    (example: background-image: url(/images/background.gif);)

    Hope this helps :)

    0 讨论(0)
  • 2021-02-20 13:24

    May be you've used backward slashes (\) instead of forward slashes (/) in the image path.

    I did this mistake and was fighting with my chrome browser. I copied the image path from Windows Explorer (which uses backward slashes)

    0 讨论(0)
提交回复
热议问题