Skip to content

Instantly share code, notes, and snippets.

@ross-u
Last active October 23, 2019 15:33
Show Gist options
  • Save ross-u/e7e76f4b6b5c2ba543ceead009996bf4 to your computer and use it in GitHub Desktop.
Save ross-u/e7e76f4b6b5c2ba543ceead009996bf4 to your computer and use it in GitHub Desktop.
CSS | position property

CSS


CSS Layout - position (static, relative, fixed, absolute, sticky)


static - All HTML elements are positioned static by default, meaning they are positioned with the flow of the page.


relative - In order to use any other postition property different than static the parent element needs to have position: relative;, so that it's children can be positioned against it via properties top, bottom, left, right.


fixed - Element gets positioned relative to the viewport.


absolute - Element is positioned relative to the nearest positioned ancestor (anyone except static ones), else uses the document body if no other non static ancestor is available.

sticky - Element is positioned based on the user's scroll position, toggles between relative and fixed.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment