The webpage background image is fixed and does not scroll with the scroll bar

Source: Internet
Author: User

What should we do when the background is a complete image and it does not move to scroll along with the scroll bar? The following is a detailed explanation.

CSSCodeExample-Background-color)

<HTML>

<Body> <p> This HTML uses the background-color attribute of CSS to change the background color of HTML to green. <P> </body>

Demo result:This HTML uses the background-color attribute of CSS to change the background color of HTML to green.
CSS sample code-Background-Image)

<HTML>

<Body style = "background-image: URL (.. /images/css_tutorials/background.jpg) "> <p> This HTML uses the background-image attribute of CSS and sets the background image. <P> </body>

Demo result:This HTML uses the CSS background-image attribute and sets the background image.
CSS code example-Background-repeat)

<HTML>

<Body> <p> This HTML uses the CSS background-repeat attribute to duplicate the background image vertically. <P> common attributes of background-repeat include repeat-X, repeat-X, and no-repeat ). </P> <p> the background-repeat attribute must be used with the background-image attribute. </P> </body>

Demo result:This HTML uses the CSS background-repeat attribute to duplicate the background image vertically. Common attributes of background-repeat include repeat-X, repeat-X, and no-repeat ). The background-repeat attribute must be used with background-image.

 

CSS code example-Background-Attachment)

<HTML>

<Body> <p> This HTML uses the CSS background-attachment attribute to fix the background image and does not scroll with the content. <P> the background-attachment attribute has two values. One is scroll, which means to move with the Content Rolling; the other is fixed, which means to be fixed and not affected by the Content Rolling. The default value is scroll. </P> <p> background-attachment must be used with background-image. </P>

</Body>

Demo result:This HTML uses the CSS background-attachment attribute to fix the background image and not scroll with the content.

The background-attachment attribute has two values. One is scroll, which means to move with the Content Rolling; the other is fixed, which means to be fixed and not affected by the Content Rolling. The default value is scroll.

Background-attachment must be used with background-image.

This HTML uses the CSS background-attachment attribute to fix the background image and not scroll with the content.

The background-attachment attribute has two values. One is scroll, which means to move with the Content Rolling; the other is fixed, which means to be fixed and not affected by the Content Rolling. The default value is scroll.

CSS sample code-Background-Position)

<HTML>

Demo result:This HTML uses the CSS background-position attribute. This attribute is used together with the background-image attribute to determine the initial position of the background image.

The above Code indicates that the initial position of the background image is 20 Px to the leftmost side of the webpage and 60 Px to the top of the webpage.

 

CSS code example-Background)

<HTML>

<Body> <p> This attribute is a quick and comprehensive method for setting background attributes, including background-color, background-image, background-repeat, backgroundattachment, and background-position. </P> <p> the background color of the HTML is green, and the background image is a background.jpg image. The background image is not displayed repeatedly. The background image does not scroll with the content. The background image is 40 PX at the left of the page and PX at the top of the page. </P>

 

</Body>

Demo result:This attribute is a quick and comprehensive method for setting background-related attributes, including background-color, background-image, background-repeat, backgroundattachment, and background-position.

The background color of the web page is green, and the background image is a background.jpg image. The background image is not displayed repeatedly. The background image does not scroll with the content. The background image is 40 Px to the left of the page and PX to the top of the page.

This attribute is a quick and comprehensive method for setting background-related attributes, including background-color, background-image, background-repeat, backgroundattachment, and background-position.

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.