What I’m saying is: everybody knows how to center things. It’s trivial. And if you are lost, the knowledge is right there. Line height is... compl

Hardest Problem in Computer Science: Centering Things

submited by
Style Pass
2024-04-16 18:30:06

What I’m saying is: everybody knows how to center things. It’s trivial. And if you are lost, the knowledge is right there.

Line height is... complicated. A canonical article to learn about it is Vincent De Oliveira’s Deep dive CSS: font metrics, line-height and vertical-align.

CSS might get in the way (different controls having different defaults which you have to undo before even starting trying to align):

Icons are like small rectangles put in line with text. Therefore all problems caused by text AND line height apply here. Aligning icons next to text is a notoriously hard task.

The problem is, CSS doesn’t help us either. There are 13 possible values for the vertical-align property, but none would align the icon in a meaningful way:

Aligning rectangles is relatively easy. Aligning text is hard. Icons are rectangles. So what if we put icons into a font file?

Neither can we set icon size! In the example above, all icons were set to the same font size and line height. As you can see, all of them come out different sizes, with different paddings, and none were properly aligned.

Leave a Comment