With CSS, how do I make an image span the full width of the page as a background image?

前端 未结 3 2002
独厮守ぢ
独厮守ぢ 2021-01-12 13:34

Say, like in this example here: http://www.electrictoolbox.com/examples/wide-background-image.html

When I do it, I end up getting white borders around the image no m

3条回答
  •  迷失自我
    2021-01-12 14:13

    If you're hoping to use background-image: url(...);, I don't think you can. However, if you want to play with layering, you can do something like this:

    
    

    And then some CSS:

    .bg
    {
      width: 100%;
      z-index: 0;
    }
    

    You can now layer content above the stretched image by playing with z-indexes and such. One quick note, the image can't be contained in any other elements for the width: 100%; to apply to the whole page.

    Here's a quick demo if you can't rely on background-size: http://jsfiddle.net/bB3Uc/

提交回复
热议问题