[css-align][css-inline] Support for aligning items to the center of the first line.
Spec links:
Premise:
I'm recently finding myself in this situation where I want to align a checkbox or a help icon to the center of the first line of the content. In some cases I was able to use align-items: center but it fails when I got a multiline paragraph.
[paragraph edited]
It seems that the only way to achieve something like this would implied making a container around the input and align visually the checkbox with the text (which could later break when the font-size/line-height change)
Proposal:
would it make sense having a property under flexbox, something like align-items: first-line-center for these cases?
I'm not sure I understand. Are you looking for align-self: first baseline?
I'm not sure I understand. Are you looking for
align-self: first baseline?
Thanks for your response :)
Not quite baseline but center relative to the first line, I'm able to use align center in some cases but it fails when I got a multiline paragraph (which tends to happens when the screen get smaller and there is less space on the container)
Single line:
Multiline:
This is the scenario that I'm trying to cover:
Checkboxes and leading icons are a classical use case. I'm solving the same issue right now in our design system:
I need the icon to visually stick to the center of the first line which is only possible when the height of the icon is the same as the line height of the text (which is luckily our case, so no padding tweaks are needed). Then both elements can be technically aligned to start. Exactly for this, an option to align the icon to the center of the first line would prove useful.
YES. This is such a common problem I run into. Huge +1 from me.
Yes, I’d love something like: align-items: first center to align elements like icons to the first line of text.
My current solution is to use align-items: first baseline to get it on the baseline, then adjust the positioning to centre it with translate: 0 calc(50% - 0.5cap) (half the difference between the icon size and text cap size; demo: https://knowler.dev/demos/d_pDxD0?codepen).