Hasty Briefsbeta

Bilingual

We finally learned to center a div, then browsers added sidebars

4 hours ago
  • Centering a div used to require absolute positioning and transform, but now can be easily done with CSS grid and place-items.
  • The author's site appeared centered only within the webview, not accounting for browser sidebar or DevTools panels.
  • The initial fix used JavaScript to compute browser chrome width and apply a translate, but it failed when DevTools was open because the total width difference was split between both sides.
  • The final solution uses pointer events to determine the viewport's position on the screen, allowing accurate offset calculation regardless of browser UI layout.
  • The author created a tool called 'center, actually' to apply this fix to any page, automatically detecting the centered element or allowing manual selection.

Related

Loading…