News for hackers. Stuff that matters.
Re:How to center a div in CSS by 4death4 on Tuesday February 13, 2024 @06:11PM (#39364154)
Maybe I missed it, but position: absolute, left: 50%, transform: translateX(-50%) is usually my go to.
Re:How to center a div in CSS by hlammers on Tuesday February 13, 2024 @08:47PM (#39365373)
I was kinda surprised that this method wasn't included in the article. While I use flexbox for centering most of the time, I still find myself resorting to the absolute positioning way sometimes.
Re:How to center a div in CSS by infensus on Tuesday February 13, 2024 @07:40PM (#39364870)
Centering like this can make your element blurry on non-hidpi screens, because transforms are not snapped to the pixel grid like layout properties, and 50% can sometimes land on a subpixel
Re:How to center a div in CSS by 4death4 on Tuesday February 13, 2024 @08:04PM (#39365068)
Is this still relevant? I thought browsers had proper support for sub-pixels now.
Re:How to center a div in CSS by infensus on Wednesday February 14, 2024 @08:19AM (#39369449)
I think this was exclusive to Chrome.

https://issues.chromium.org/issues/40431598

Seems like they managed to kinda fix it in some cases, but some of the reproductions provided in the issue tracker are still working, so I would be careful

Re:How to center a div in CSS by wruza on Tuesday February 13, 2024 @08:28PM (#39365239)
What do you do when position isn’t absolute?
Re:How to center a div in CSS by 4death4 on Wednesday February 14, 2024 @12:00AM (#39366688)
Then I use one of the approaches listed. However, I find that usually I want absolute positioning when centering either horizontally or vertically.