Setting background Image for DIV

I have a div, which I need to set a background image for in the CSS file:

Template:

<div class="myBG">  Some Text Here </div>

CSS:

.myBG{
    background-image: url('ImageURL');
    color: #00FA9A;
    font-family:Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
    width: 100%;
    height: 100%;
}

To set ImageURL I tried web links as well as links to images on my disk, but it does not work and I do not get any background to my div. Can you find out what is wrong with my code?

Upvotes: 1

Views: 171

Answers (1)

DrNio
DrNio

Reputation: 1976

You need to position the background for example: background: blue url("ImageURL.png") no-repeat center center; , specify the size of the background with background-size: cover; or with pixels instead of cover, make sure that the computed width and height values of the div are not 0 and that there is no 404 error while trying to fetch the image from the server.

Upvotes: 1

Related Questions