Home > Back-end >  <div> not displaying background image
<div> not displaying background image

Time:03-09

In my css file, I have an id named "homehero", which displays a background image.

#homehero 
    {
        background-image: url("images/coast.jpg");
        background-size: 100% 100%;
        background-repeat: no-repeat;
    }

In my html file, I have a div that uses this id to display the image; however, the image does not appear whatsoever.

<div id="homehero"> <!-- Home Page Image -->
    <!-- <img src="images/coast.jpg" width="100%" height="100%" alt="A Sunny Coastline"> -->
    <!-- Old line of html that displayed the same image, but converted to css id. -->
</div> <!-- End of Home Page Image -->

The full html file can be found here.

The full css file can be found here.

Edit: The image is displayed when setting it as the background image for another element, it is only in this id where the issue occurs.

CodePudding user response:

Please Put width and height width:100%; height:100vh;

#homehero 
    {
        background-image: url("images/coast.jpg");
        background-size: 100% 100%;
        background-repeat: no-repeat;
        width:100%; 
        height:100vh;
    }

CodePudding user response:

it looks like you're entering the url in the background image, for background size using background-size: cover;

CodePudding user response:

These are a few things I recommend you try:

  • Try setting the background size. (Instead of %, try setting it to px.) Most of the time, the background picture is applied, but because our div has no dimension, we are unable to view it.
  • Double-check that your picture file is located in the images folder.
  • Check your image's extension and make sure you're using the correct one in your code.
  • Use the dev tools to inspect the element and see whether the background property is being overridden by another CSS rule.

If none of the above methods work, try pasting the picture's real URL by copying the image address from the internet rather than providing a folder path. This method works 90% of the time.

  • Related