Less Absolute Positioning With Modern CSS

Ahmad Shadeed blogs the sentiment that we might not need to lean on position: absolute as much as we might have in the past. For one thing: stacking elements. For example, if you have a stack of elements that should …


The post Less Absolute Positioning With Modern CSS appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

Ahmad Shadeed blogs the sentiment that we might not need to lean on position: absolute as much as we might have in the past. For one thing: stacking elements. For example, if you have a stack of elements that should all go on top of each other…

.stack {
  display: grid;
}
.stack > * {
  grid-area: 1 / -1;
}

All the elements occupy the same grid cell at that point, but you can still use alignment and justification to move stuff around and get it looking and behaving how you want.

What you are really saying with position: absolute is I want this element to be entirely removed from the flow such that it doesn’t affect other elements and other elements don’t affect it. Sometimes you do, but arguably less often than your existing CSS muscle memory would have you believe.

I’ll snag one of Ahmad’s idea here:

Both the tag and the title are positioned in a way we might automatically think of using absolute positioning. But again, something like CSS Grid has all of the alignment features we need to not only stack them vertically, but place them right where we want.

Direct Link to ArticlePermalink


The post Less Absolute Positioning With Modern CSS appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-10-13T14:42:26+00:00) Less Absolute Positioning With Modern CSS. Retrieved from https://www.scien.cx/2021/10/13/less-absolute-positioning-with-modern-css-2/

MLA
" » Less Absolute Positioning With Modern CSS." Chris Coyier | Sciencx - Wednesday October 13, 2021, https://www.scien.cx/2021/10/13/less-absolute-positioning-with-modern-css-2/
HARVARD
Chris Coyier | Sciencx Wednesday October 13, 2021 » Less Absolute Positioning With Modern CSS., viewed ,<https://www.scien.cx/2021/10/13/less-absolute-positioning-with-modern-css-2/>
VANCOUVER
Chris Coyier | Sciencx - » Less Absolute Positioning With Modern CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/13/less-absolute-positioning-with-modern-css-2/
CHICAGO
" » Less Absolute Positioning With Modern CSS." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/10/13/less-absolute-positioning-with-modern-css-2/
IEEE
" » Less Absolute Positioning With Modern CSS." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/10/13/less-absolute-positioning-with-modern-css-2/. [Accessed: ]
rf:citation
» Less Absolute Positioning With Modern CSS | Chris Coyier | Sciencx | https://www.scien.cx/2021/10/13/less-absolute-positioning-with-modern-css-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.