Page background picture stretch

Source: Internet
Author: User

There are two ways to resolve this:

One is CSS, using background-size:cover to achieve the image stretching effect, but IE8 and the following version does not support Background-size, so you can use the Microsoft filter effect, but IE6 does not support.

Body {background:URL (bg.jpg) center Center; background-size:cover; height:900px; width:100%; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src= ' bg.jpg ', sizingmethod= ' scale ') 

The other is to use jquery to dynamically insert a div in the body, and then include a picture in the Div, and the size of the background image is dynamically set when the browser window is resized.

$(function(){     $("Body"). Append ("<div id= ' main_bg ' style=" Position:absolute; " /> "); $("#main_bg"). Append (");     Cover (); $ (window). Resize (function(){//browser window Changescover (); }); }); functioncover () {varWin_width =$ (window). width (); varWin_height =$ (window). Height (); $("#bigpic"). attr ({width:win_width,height:win_height}); } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.