CSS - background-attachment
background-attachment
The background-attachment
property defines if a background image of an element scrolls with the page or is fixed to the background.
Property Variable Name
background-attachment
Available Values for background-attachment
scroll|fixed|local|initial|inherit
Examples Using background-attachment values
Example using background-attachment scroll
Example using background-attachment scroll
Here is an example using background-attachment:scroll;
Code
<style>
.demo-box-1 {
border-radius:3px;
margin-bottom:10px;
border:1px solid #000;
height:220px;
width:100%;
display: flex;
flex-wrap: wrap;
background:url(https://css.kruxor.com/images/pexels-photo-4279015.jpeg);
background-size:cover;
background-attachment:scroll;
}
</style>
<h2>Example using background-attachment scroll</h2>
<p>Here is an example using <code>background-attachment:scroll;</code></p>
<div class='demo-box-1'>
</div>
Example using background-attachment fixed
Example using background-attachment fixed
Here is an example using background-attachment:fixed;
Code
<style>
.demo-box-2 {
border-radius:3px;
margin-bottom:10px;
border:1px solid #000;
height:220px;
width:100%;
display: flex;
flex-wrap: wrap;
background:url(https://css.kruxor.com/images/pexels-photo-4279015.jpeg);
background-size:cover;
background-attachment:fixed;
}
</style>
<h2>Example using background-attachment fixed</h2>
<p>Here is an example using <code>background-attachment:fixed;</code></p>
<div class='demo-box-2'>
</div>
Example using background-attachment local
Example using background-attachment local
Here is an example using background-attachment:local;
Code
<style>
.demo-box-3 {
border-radius:3px;
margin-bottom:10px;
border:1px solid #000;
height:220px;
width:100%;
display: flex;
flex-wrap: wrap;
background:url(https://css.kruxor.com/images/pexels-photo-4279015.jpeg);
background-size:cover;
background-attachment:local;
}
</style>
<h2>Example using background-attachment local</h2>
<p>Here is an example using <code>background-attachment:local;</code></p>
<div class='demo-box-3'>
</div>
Example using background-attachment initial
Example using background-attachment initial
Here is an example using background-attachment:initial;
Code
<style>
.demo-box-4 {
border-radius:3px;
margin-bottom:10px;
border:1px solid #000;
height:220px;
width:100%;
display: flex;
flex-wrap: wrap;
background:url(https://css.kruxor.com/images/pexels-photo-4279015.jpeg);
background-size:cover;
background-attachment:initial;
}
</style>
<h2>Example using background-attachment initial</h2>
<p>Here is an example using <code>background-attachment:initial;</code></p>
<div class='demo-box-4'>
</div>
Example using background-attachment inherit
Example using background-attachment inherit
Here is an example using background-attachment:inherit;
Code
<style>
.demo-box-5 {
border-radius:3px;
margin-bottom:10px;
border:1px solid #000;
height:220px;
width:100%;
display: flex;
flex-wrap: wrap;
background:url(https://css.kruxor.com/images/pexels-photo-4279015.jpeg);
background-size:cover;
background-attachment:inherit;
}
</style>
<h2>Example using background-attachment inherit</h2>
<p>Here is an example using <code>background-attachment:inherit;</code></p>
<div class='demo-box-5'>
</div>