DEV Community

Discussion on: Do you still use "position" to center align vertically and horizontally?

Collapse
 
deroldo profile image
João Vitor Bragion Deroldo de Oliveira

I use flex in all my projects, but i had a trouble these days, i was making an header with tree elements, so i had this:

when i set: justify-content: space-between the logo was misaligned because is smaller than so it was necessary to align the with position absolute and trasnform to center it exactly in the header.

Collapse
 
titungdup profile image
dhondup

Interesting! I would love to see a codepen demo if you are willing to create one.

Collapse
 
deroldo profile image
João Vitor Bragion Deroldo de Oliveira

Take a look at this pen: codepen.io/joaoskr/pen/eYmPNBG

If you remove this properties from domain-toggle class, you'll see what i said about alignment:
position: absolute;
left: 50%;
transform: translateX(-50%);

Thread Thread
 
titungdup profile image
dhondup

That's a nice use case for position alignment. I think it would be difficult to achieve that result with any other method.