How CSS sets a full-screen background picture

Source: Internet
Author: User

If you have a more gorgeous picture want to do background, you can set this:

The

code is as follows: body{Background:url (img.jpg); background-position:center; background-repeat:no-repeat;} But the effect is likely to be this: pictures are not overlapping, centered, and ... She is too young to occupy all the pages.


Unfortunately, there is no picture in the CSS2 full screen stretching properties, so I think of a way.


uses a div layer to load an IMG tag inside. The DIV and IMG are then set to a size of 100% and pinned to the bottom of the screen, thus achieving the perfect stretch and maximizing the image's purpose.


first in the body to add the following code: Code as follows: <div id= "Div1" ></div& Gt then add CSS code:

div#div1{position:fixed; top:0; left:0; bottom:0; right:0; z-index:-1;} div#div1 &gt; img {height:100%; width:100 %; border:0; Final effect: Stretch The browser, adjust the page position, the picture background picture is still centered full screen: The effect of the Fox: This, We achieved a fixed-centered and automatically stretched Full-screen background image, but she is a layer, so when the user in the margin of the page when the right button, the display is the picture information, which may make the user feel inconvenient.


In fact, Firefox's tensile effect is much stronger than IE, will automatically feather the details of the picture. IE in the image after stretching the pixel is very ugly, so it is recommended to use high-resolution images as the background.


Novice to, expert Please guide, thank you.

Related Article

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.