2
When declaring a div and importing an image as background-image
, it is necessary that I declare the size(height
and width
) of the div.
However, let’s say I have an image with the size 900x506(example). And I just declared div
and assigns no size(height
and width
) to her.
It is possible for me to import the image via css background-image: url('minhaimagem.jpg');
and my div will automatically display it, even though I have not assigned any size(height
and width
) to her?
(I do not know if it was very clear, another explanation..)
Is it possible for me to declare a div
, import an image as background
and my div
"take" the values of my image(height
and width
)?
#imagem{
background-image: url('http://www.planwallpaper.com/static/images/techno_wallpaper_2_0_hd_by_gredius-d5o48do.jpg');
}
<div id="imagem">
</div>
The snippet is not working /:
– Zkk
here is normal, which browser is using? IE8?
– Tobias Mesquita
I’m using Google Chrome, it doesn’t work. I tried in Edge for doubt and it worked. In Javascript there is some kind of browser compatibility feature similar to css (Webkit and among others)?
– Zkk
@Zkk, I am running on an old version of Chrome (35) and am not finding problems... in any case I made a small change.
– Tobias Mesquita
I tested on Chrome/firefox and worked on both.
– Renan Gomes