Webpage background image stretching-jerrylsxu

Source: Internet
Author: User
Webpage background image stretching-jerrylsxu provides two solutions:

One is CSS, which uses background-size: cover to achieve image stretching. However, IE8 and earlier versions do not support background-size, so Microsoft filters can be used, however, IE6 does not.

Body {background: url(bg.jpg) center; background-size: cover; height: 900px; width: 100%; filter: progid: weight', sizingMethod = 'Scale ');}

The other is to use jQuery to dynamically insert a p in the body, and then include an image in p. the browser window is changed by an hour and the size of the background image is dynamically set.

$ (Function () {$ ("body"). append ("

"); $ (" # Main_bg "). append (""); cover (); $ (window ). resize (function () {// cover ();}); function cover () {var win_width = $ (window ). width (); var win_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.