css perfect full screen image background

后端 未结 2 919
北海茫月
北海茫月 2020-12-30 08:09

I\'m wondering which is the best solution for an background image to fit every screen, every browser. Also I\'ve noticed that the majority of techniques crop the image a lit

相关标签:
2条回答
  • 2020-12-30 08:55

    Add this inside the body tag:

    <img src="img/beach.jpg" 
    
    style="width:100%;height:100%;position:absolute;top:0;left:0;z-index:-5000;">
    

    http://thewebthought.blogspot.com/2010/10/css-making-background-image-fit-any.htmlg

    0 讨论(0)
  • 2020-12-30 08:56

    This post from CSS-tricks.com covers different techniques for full screen background images and includes a fall-back for old versions of IE (I haven't tested the IE fix).

    When I don't need to worry about supporting old browsers, I generally use the CSS3 method:

    html { 
        background: url(http://lorempixum.com/1440/900/sports)
            no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    
    0 讨论(0)
提交回复
热议问题