💻 Código HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/background.css">
<title>Document</title>
</head>
<body>
<h2>scroll (<code>default</code>)</h2>
<div class="scroll"><div class="expand"></div></div>
<h2>scroll (<code>fixed</code>)</h2>
<div class="fixed"><div class="expand"></div></div>
<h2>scroll (<code>local</code>)</h2>
<div class="local"><div class="expand"></div></div>
<br class="extra-space">
</body>
</html>
🎨 Código CSS
h2 {
text-align: center;
margin-top: 48px;
}
div {
height: 200px;
width: 50%;
max-width: 600px;
margin: 32px auto;
overflow-x: hidden;
overflow-y: scroll;
}
.scroll {
background: url('https://picsum.photos/700?id=1');
background-attachment: scroll;
}
.fixed {
background: url('https://picsum.photos/700?id=2');
background-attachment: fixed;
}
.local {
background: url('https://picsum.photos/700?id=3');
background-attachment: local;
}
.expand {
height: 400px;
width: 100%;
}
.extra-space {
margin-bottom: 50px;
}