I want to load an image to a tag img
from a css file
The following code is from my HTML
<img class="logo-header" alt="tienda online"/>
and then the css
img.logo-header{background: url("../img/centro.jpg");}
my file folders are structured like this
I can't get the image to load, I don't know if I'm doing something wrong or if I should upload the page to a hostinger and place the image in this way
img.logo-header{background: url("https://www.test.com/img/centro.jpg");}
There are more rules in my CSS file, it is ruled out that it is not connected correctly to the style sheet.
In the html I recommend you replace:
By
In the style replace:
By
Another option is to work with the content attribute
I did the test and it works correctly in the following browsers:
Except:
PS: I missed testing in Opera and IE
If your tag
<img class="logo-header" alt="tienda online"/>
is in the fileindex.html
, the path to your image is:img/centro.jpg
.Now, if you want to place a background image, you can do it directly in a div like this (and this is just an example):