100% background image

Source: Internet
Author: User

First, let's take a look at the demo (the background image is automatically scaled when the browser window size is changed)

Code Parsing

Main HTML code

<Div>

</Div>
<Div id = "fixed">
<P> the background image is always 100% x 100% (Body Size). But it only works with a 100% x 100% html/body. </P>

</Div>
<Div id = "scroller">
<Div id = "content">
Document content .....
</Div>
</Div>

As you can see from the code above, the image, the small text on the left, the main content of the document is three Div distribution, is the main three frameworks.
Next, let's take a look at the relevant CSS code.

HTML, body {margin: 0; padding: 0; width: 100%; Height: 100%; overflow: hidden ;}
/* Set the global style of HTML and body labels, with no internal and external spacing and full length and width of 100%. When overflow occurs, the system automatically extends to hide the internal scroll bar */

Body {font-family: verdana, Arial, sans-serif; font-size: 76% ;}
/* Set the global font and size */

# Background {position: absolute; Z-index: 1; width: 100%; Height: 100% ;}
/* Place the DIV of the image to be absolutely positioned. The zcoordinate is 1 and the automatic length and width */

# Scroller {position: absolute; width: 100%; Height: 100%; top: 0; left: 0; overflow: auto; Z-index: 2 ;}
/* The External Frame of the main content is also full 100% long and wide. Positioning occupies the full screen. The zcoordinate is a layer higher than the image Div, so it is above the image, and when the DIV content exceeds the range, the scroll bar is displayed */

# Content {padding: 5px 300px 20px 200px ;}
P {Line-Height: 1.8em; letter-Spacing: 0.1em; text-align: justify ;}
/* Set the style of the content. With left and right internal patches, the left and right scroll bars are not displayed */

# Fixed {position: absolute; top: 25px; left: 10px; width: 150px; Z-index: 10; color: #567; Border: 1px solid #000; padding: 10px ;}
/* Set the DIV in the upper left corner. The zcoordinate is 10.

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.