开发者

Background image that always scales so that any normal background color wouldn't appear

I wonder if 开发者_如何学Gothere is a hack that would resize the image in the way that it would always cover the whole browser window. It should also keep the image´s aspect ratio.


this website http://css-tricks.com/how-to-resizeable-background-image/ has a great writeup on this.

Basically just use as the style for your bg

#bg {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

About your requirement to maintain the aspect ration AT THE SAME TIME as make it cover the whole window, I don't think it's achievable, you either sacrifice aspect ratio or coverage


try this code through jquery

 var docHeight = Math.max(

            $(document).height(),

            $(window).height(),

            /* For opera: */

            document.documentElement.clientHeight

        );

        var docWidth = Math.max(

            $(document).width(),

            $(window).width(),

            /* For opera: */

            document.documentElement.clientWidth

        );

        $("selector").css({

            "height":docHeight,

            "width":docWidth

        });                
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜