Background image does not appear in div without content

1

I'm creating an empty div with a background image. But when I render the site, the div does not appear. I believe that the error happens for not having content in the div.

In this case how could I proceed?

    
asked by anonymous 25.10.2014 / 23:32

1 answer

4

Set the width and height of the image. In the example I inserted a 500x500 size image, then the width and height properties will be equivalent to 500px . Probably what was missing in your CSS code was the background alignment in the center using the background-position:center; property.

Please note:

.minhaDiv 
{
   background-image: url('https://g.twimg.com/Twitter_logo_blue.png'); /* endereço URL da imagem */
   background-position:center; /* centraliza apenas o background - para não cortar */   
   height: 500px; /* defina a largura da imagem */
   width: 500px; /* defina a altura da imagem */
   background-repeat:no-repeat; /* para não repetir o background */
}
<div class="minhaDiv"></div>
    
26.10.2014 / 00:04