I can not call an image from CSS

0

Why can not I call an image from the css when I have the css file inside a folder? (I tried putting it in a folder to order).

I'm trying to call an image that I have in an IMG folder but it will not let me, but when I have the "messy" css file without being in any folder, it lets me call it without problem?

I am trying to call it in the following way.

.imagen-fondo{
background:url(https://img-aws.ehowcdn.com/600x375/photos.demandstudios.com/getty/article/147/118/71031242.jpg);
height:500px;
width:500px;
}
<div class="imagen-fondo">

</div>
    
asked by Victor Escalona 28.06.2018 в 03:31
source

2 answers

1

If your css file and your image do not share the same directory, you must place the correct instruction to link the image:

Then, your "styles.css" file is in the "css" folder, and your "fondo.jpg" file is in the "img" folder, then when you link the background image from the "styles.css" file "you must go back to the root to be able to access the" img "folder, this you do by placing" ../ "at the beginning of the path of your image:

background: url("../img/fondo.jpg");

I hope it serves you. Greetings!

    
answered by 28.06.2018 / 05:11
source
0

Are you calling the image by link? When you call an image that is hosted on your computer, be sure to indicate the subfolder where it is located. That is, if you create a folder called "img". For example you set the src as "img / example.jpg".

    
answered by 28.06.2018 в 03:55