Why doesn't the background image show up without specific width and height?

后端 未结 5 2013
星月不相逢
星月不相逢 2020-12-16 16:24

Here\'s an example code

I\'ve been wondering why the background-image doesn\'t show up unless I specific the image\'s width and height in pixels. I trie

5条回答
  •  臣服心动
    2020-12-16 17:06

    Your background image will not show because the div element has no content, this means that its height is 0.

    You could use this jQuery code to make your div take the size of the window.

    $(function () {

    'use strict';
    $('.div').height($(window).height());
    
    $(window).resize(function () {
        $('.div').height($(window).height());
    
    })
    

    });

提交回复
热议问题