I am facing the problem with possibility to make only one area sticky in the CSS grid.
How it looks in the code:
.wrapper {
display: grid;
gap: 32;
grid-template-columns: 1fr 478px;
grid-template-areas:
'Images Details'
'Tabs Tabs';
}
.child1 {
grid-area: Images;
}
.child2 {
align-self: flex-start;
grid-area: Details;
position: sticky;
top: 0;
}
.child3 {
grid-area: Tabs;
}
So the section Images
is much bigger (bigger height) than Details
and what I want to achieve is to make Details
sticky when scrolling down, but once I reach the bottom of Images
it should stop moving down. For now area Images
overlaps Tabs
because it is sticky for the wrapper.
Any idea how to fix it?
Demo
https://stackblitz.com/edit/web-platform-a8znlr?file=styles.css
2
Answers
I think this will fix your problem.
The solution you request is not achievable with pure css and html, however you can do this with some javascript: