CSS Stretched Background Image

后端 未结 4 837
滥情空心
滥情空心 2021-01-12 09:28

I have a large image to be use as a background-image of a page. What I want is that the height of the image will be stretched to fill the height of the page. It

相关标签:
4条回答
  • 2021-01-12 10:10

    I think using a div would be the easiest way to get the effect you are looking for.

    <div id="background">
        <img src="/image/background.jpg" class="stretch" alt="" />
    </div>
        <style>
        #background {
            background-color:#000000;
            width: 100%; 
            height: 100%; 
            position: fixed; 
            left: 0px; 
            top: 0px; 
            z-index: -1;
        }
    
        .stretch {
            width:100%;
            height:100%;
        }
        </style>
    
    0 讨论(0)
  • 2021-01-12 10:17

    background-size: cover will do the trick in modern browsers - see mozilla's documentation for more details.

    For older browsers (particularly older versions of IE), I've had a lot of success with jQuery plugins like this one to emulate the behaviour.

    0 讨论(0)
  • 2021-01-12 10:25

    here is a good writeup

    http://css-tricks.com/perfect-full-page-background-image/

    the gist of it being

    body { 
    background: url(images/bg.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    }
    
    0 讨论(0)
  • 2021-01-12 10:25

    add this to the css

    {
    background: black url("/image/background.jpg") no-repeat fixed center;
    height: 100%;
    width:100%
    }
    
    0 讨论(0)
提交回复
热议问题