skip to Main Content

I’m developing a sub page for my website. I have a nav bar and footer. I just want to add a background image behind the nav bar just like this.

enter image description here

I tried ..

<div class="seo-content"></div>

.seo-content{
  background: url("/images/ss.jpg");
  background-size: cover;
}

But It’s not working as expected.

Now it showing like this way ..

enter image description here

If I add height property, it showing up. But I need to sketch actual image size to the screen. That’s why I used background-size: cover;

What’s wrong with my code?

3

Answers


  1. Use to following code:

     .seo-content {
       background: url("w3schools.com/css/bgdesert.jpg");
       background-size: cover;
       width: 100%;
       height: 100%;
       position: fixed;
       top: 0;
       left: 0;
       z-index: 0;
     } 
    
    Login or Signup to reply.
  2. Is the div possibly a child of a floating div container?
    If it’s the child of a floating div or enclosing element it would have zero height thus not showing the image.

    Try inspect element to gain a bit more detail?

    Login or Signup to reply.
  3. Try to set a fixed hight:

    .seo-content{
      background: url("/images/ss.jpg");
      background-size: cover;
      height: 200px;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search