css position: sticky

This links highlights what's new in Chrome 56:


One cool thing amongst others (bluetooth access is also cool but this one css feature is something I wish we had a while back) is position:sticky.

It's available in Chrome 56 (stable as of Jan 2017) and to summarize, it allows to fix an element into the viewport when it's within a threshold.

.header {
 // Element will be "fixed" when it is 10px from the top of the viewport
 top: 10px

You could set top : 0; to make it stick directly to the top of the viewport.

Have to be conscious that this positioning might not be available in other browsers as of yet.

There's this site I use to check what's available: http://caniuse.com/#search=sticky

As of now, it's not available in IE (not very surprising...)


Popular posts from this blog

Git commands cheat sheet (in progress)

async promises in a sync way?

HTML5 Dev Conf and IOTAConf