-3

Whats wrong with following code, why is background image not showing:

HTML

<div class="logo"> E  </div>

CSS

.logo
{
    height: 100%;
    width: 100%;
    background-image: url("/banner.svg");
}

No rocket science, by using Brackets editor, simply trying to add background-image to a div. Image file is in the same folder as .html and .css file.

esqew
  • 42,425
  • 27
  • 92
  • 132
Oxin
  • 31
  • 1
  • 7

7 Answers7

1

i assume your image-link is wrong. You could try to colorize the background to see if its really image related:

background-image: linear-gradient(red, yellow, blue);
iHalla
  • 64
  • 4
  • sure your linear-gradient is showing up on the div. why the hell is my given path wrong and why the hell is whole web is filled with the "WRONG PATH" answer? – Oxin Mar 31 '22 at 12:11
  • 1
    @Oxin you can be mad all you want but that doesn't change the reality of the situation. – siride Mar 31 '22 at 12:50
0

I think your image path maybe wrong

You better try this

CSS

.logo {
    height: 100%;
    width: 100%;
    background-image: url("./banner.svg");
}
Afshar Sharifi
  • 152
  • 1
  • 7
0

As your image is in the same folder as your code you don't need that /

<div class="logo"> E  </div>
CSS

.logo
{
    height: 100%;
    width: 100%;
    background-image: url("banner.svg");
}
A Haworth
  • 30,908
  • 4
  • 11
  • 14
0

There seems to be no problem in the code. The url to the image must be wrong. Check the path again. NOTE:

  • / is the root of the current drive;

  • ./ is the current directory;

  • ../ is the parent of the current directory.

Prateek p
  • 117
  • 1
  • 11
0

The code looks okay but you might want to check the image URL. "/banner.svg" means the image is in the same directory as the CSS file, if it's not then correct the image URL. You might also want to check the image extension is it really svg or png? If you think the URL is correct then try adding a background color of red to the logo class and you'll know where the issue lies.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 31 '22 at 10:24
  • `background-color` property is easily set on div but `background-image` is unnecessarily not working. I have made sure to check .svg extension as well as its placement in the same folder as .cs file. no fruits – Oxin Mar 31 '22 at 12:28
0

Double check your image path and consider adding:

.logo {
  background-image: url(banner.svg);
  background-position: 100% 100%;
  background-size: cover;
}
isla_just
  • 41
  • 6
-1

Ah, if you run it just on a static HTML but not in a server, you can modify like this:

 background-image: url("banner.svg");
nexus
  • 1
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 31 '22 at 10:28
  • dont know what u r trying to say – Oxin Mar 31 '22 at 12:43