Using Position Sticky With CSS Grid


Say you’ve got a two-column CSS grid and you want one of those columns to behave like position: sticky;. There is nothing stopping you from doing that. But the default height for those two columns is going to be “as tall as the tallest content in either column” because the default behavior for grid columns is align-items: stretch;. So, even if you have really “short” content in the column you want to behave as sticky, it won’t appear to move because really it’s already as tall as the other column.

Ahmad Shadeed makes the point that if you want that to work, you’ll probably need to align-items: start; the one you want to behave as sticky.

I would add that if you want position: sticky; behavior for elements inside either of the columns, then you’ll actually want to leave the default stretch behavior alone. Here’s an example of what I mean there as a fork:

Direct Link →

Source link


Please enter your comment!
Please enter your name here

Share post:




More like this

Announcing 4 new Membership templates — and a cyber week sale!

From portfolios to business sites and everything in-between,...

5 Ways to Make Your JavaScript More Functional

In this article, we’ll explain a little bit...

What is the Glassmorphism Web Design Trend?

If you think you haven’t heard of glassmorphism,...

Free Christmas Icons Set – Designmodo

Freebies • Iconsandrian • October 05, 2022 •...