I wanted to show the parent gradient just from child shape.
I tried adding ::after
to parent with white background to hide parent background color, but then child’s background also becomes white.
Currently:
#parent {
background: linear-gradient(#e66465, #9198e5);
width: 100px;
height: 300px;
}
.child {
position: relative;
width: 50px;
height: 50px;
border: 1px solid blue;
border-radius: 50%;
color: white;
}
.top-10 {
top: 10px;
}
.top-20 {
top: 20px;
}
.top-40 {
top: 40px;
}
.top-60 {
top: 60px;
}
<div id="parent">
<div class="child top-10"></div>
<div class="child top-20"></div>
<div class="child top-40"></div>
<div class="child top-60"></div>
</div>
Expected:
Also the child positions are changeable.
2
Answers
The parent element does not set other styles. The child element adds two important style attributes: background: linear gradient (# e66465, # 9198e5);background-attachment: fixed;. the gradient is used for four circles respectively.
all style codes:
be careful:
background-attachment:fixed
https://developer.mozilla.org/en-US/docs/web/css/background-attachment
This is my solution:
Another solution with background that is not changing on scroll: