पृष्ठभूमि में छवि के स्क्रॉलिंग को सेट करने के लिए, background-attachment गुण का उपयोग करें।
उदाहरण
निम्न कोड चलाकर देखें कि background-attachment गुण कैसे काम करता है:
<!DOCTYPE html> <html>
<head>
<style>
body {
background-image: url('/css/images/css.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-attachment: scroll;
}
</style>
</head>
<body>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
</body>
</html>
नोट: उदाहरण में background-attachment दो बार घोषित किया गया है; अंतिम मान (scroll) प्रभावी होगा। fixed मान छवि को व्यूपोर्ट के सापेक्ष स्थिर रखता है, जबकि scroll (डिफ़ॉल्ट) इसे सामग्री के साथ स्क्रॉल करता है।