0

Why background image is not appearing? I am trying to add background image in a container and text over it in the middle. But image is not appearing.

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    .bgContainer {
      background-image: url("https://images.unsplash.com/photo-1470219556762-1771e7f9427d?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MXx8YnVpbGRpbmd8ZW58MHx8MHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60");
      background-color: aliceblue;
      background-blend-mode: overlay;
      background-size: 100% 100%;
      height: 50%;
    }
    
    .frContainer {}
  </style>
</head>

<body>
  <div class="container">
    <div class="col-md-12 bgContainer">
      <div class="col-md-12 frContainer">
        Header for Image!
      </div>
    </div>
  </div>
</body>

</html>
dhruw lalan
  • 791
  • 1
  • 11
  • 23
Ash
  • 91
  • 3
  • 11
  • 2
    it is working, if you change the height of your background div, you will see it : https://jsfiddle.net/14h7jrko/ – Vincent G Jan 03 '21 at 18:10

2 Answers2

0

Problem

You are trying to apply a background image without a specific width and height

Possible solutions

Specify width and height properties to your container CSS styles.

width: 100%;
height: 100vh;

Code

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
            .bgContainer{
                background-image: url("https://images.unsplash.com/photo-1470219556762-1771e7f9427d?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MXx8YnVpbGRpbmd8ZW58MHx8MHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60");
                background-color:aliceblue;
                background-blend-mode: overlay;
                background-size: 100% 100%;
                width: 100%;
                height: 100vh;
            }
            .frContainer{
                
            }
        </style>
    </head>
    
    <body>
        <div class="container">
            <div class="col-md-12 bgContainer">
                <div class="col-md-12 frContainer">
                    Header for Image!
                </div>
            </div>
        
        </div>
    
    </body>
</html>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Esaú Morais
  • 82
  • 2
  • 9
0

try this

.bgContainer{
            background-image: url("https://images.unsplash.com/photo-1470219556762-1771e7f9427d?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MXx8YnVpbGRpbmd8ZW58MHx8MHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60");
            background-color:aliceblue;
            background-blend-mode: overlay;
            background-size: cover;
            height:100vh;
        }
NTIC TECH
  • 116
  • 1
  • 9