1

My background image for the div won't load in even thou everything is correct, it'll only load when I type something on it.

HTML Code ~

<!DOCTYPE html>

<html>
<head>
<link rel="stylesheet" type="text/css" href="Index.css">
<link href="https://fonts.googleapis.com/css2?family=Montserrat&family=Oswald&family=Roboto:wght@300&family=Ubuntu:wght@300&display=swap" rel="stylesheet">
</head>
<body>

<div id="Header">



</div>

</body>
</html>

CSS Code

body {

    background-color: #FEF991;
    margin: 0px;
    paddng: 0px;

}

#Header {

    background-image: url("A.png");

}

The files are correct and everything but it'll only load in when I write something I have no idea why or how to fix it.

1
  • is A.png located within an image folder or main project directory? Also you may want to give some width and height dimensions to #header Commented May 16, 2020 at 15:52

3 Answers 3

2

The container will compute to a 0px if there are no explicit dimensions provided for it or content. Applying a height to your #Header element will fix your problem.

Sign up to request clarification or add additional context in comments.

Comments

0

Your header doesn't have height or width, and by default it will not be displayed until you add some HTML elements to it or adding style height and width, try adding this to header style:

#Header {
    background-image: url("A.png");
    height: 100px;
    width: 100%;
}

working snippet:

body {
  background-color: #FEF991;
  margin: 0px;
  paddng: 0px;

}

#Header {
    background: rgba(0, 0, 0, 0.5);
    height: 100px;
    width: 100%;
}
<!DOCTYPE html>

<html>
<head>
<link rel="stylesheet" type="text/css" href="Index.css">
<link href="https://fonts.googleapis.com/css2?family=Montserrat&family=Oswald&family=Roboto:wght@300&family=Ubuntu:wght@300&display=swap" rel="stylesheet">
</head>
<body>

<div id="Header">


</div>

</body>
</html>

1 Comment

Glad to help, please consider accepting answer if you find any of the answers useful :)
0

This is because the div's height is 0%. whenever you add some text to it, div's size increases and so you are able to see the background image.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.