Skip to content

CSS absolute centering for elements with variable dimensions

iclanzan.com
2 pointsspleeder1 comment
On HN

Comments

This is a much better solution for non-trivial cases than any in the absolute centering article. The only competitor is the table-cell technique with vertical align center; but that requires more markup, and there is some tricky interaction with the outer display:table since table-displayed element follow different sizing rules (basically, you can't position:absolute them with 0 top/left/right/bottom offsets since their intrinsic size overrides such declarations).

In short: the ghost element technique works best :-).

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.