Adding background image to div using CSS

后端 未结 8 1738
终归单人心
终归单人心 2020-12-24 02:09

I have been trying to add background image to a div class using CSS, but I didn\'t have any success.

HTML code:

8条回答
  •  感情败类
    2020-12-24 02:29

    You need to add a width and a height of the background image for it to display properly.

    For instance,

    .header-shadow{
        background-image: url('../images/header-shade.jpg');
        width: XXpx;
        height: XXpx;
    }
    

    As you mentioned that you are using it as a shadow, you can remove the width and add a background-repeat (either vertically or horizontally if required).

    For instance,

    .header-shadow{
        background-image: url('../images/header-shade.jpg');
        background-repeat: repeat-y; /* for vertical repeat */
        background-repeat: repeat-x; /* for horizontal repeat */
        height: XXpx;
    }
    

    PS: XX is a dummy value. You need to replace it with your actual values of your image.

提交回复
热议问题