Repository navigation
Why are the Icon components "display: block" by default and not "display: inline-block"? #4189
|
Hey everyone, |
Replies: 2 comments 2 replies
|
Good question! I’m not entirely sure, but I think it may be kind of by accident. The icon component originated as an internal component we used for the icons Starlight rendered in different places in its UI. In #254 we then decided to expose that as a component users could access (released in v0.4). My guess is that |
|
There is a good reason to keep it, even if it started out as an accident. An inline SVG is a replaced element, so in an inline formatting context it sits on the text baseline and the line box still reserves the descender space under it. You get a few extra pixels below every icon, and a parent that is sized to the icon ends up taller than the icon. The catch is the one you hit: for an icon sitting in a run of text, .sl-icon-inline {
display: inline-block;
vertical-align: -0.125em;
}That puts a 1em icon on roughly the x-height optical centre. Tune the value per typeface, it is not universal. No idea whether flipping the default would be safe here, since every internal usage inside a flex container would need checking, and the ones relying on the block behaviour would silently gain that descender gap back. |
Good question! I’m not entirely sure, but I think it may be kind of by accident.
The icon component originated as an internal component we used for the icons Starlight rendered in different places in its UI. In #254 we then decided to expose that as a component users could access (released in v0.4).
My guess is that
blockwas a perfectly reasonable choice when the icons were being used insidedisplay: flexcontainers pretty much universally and when we made the component public, we did not reconsider this.