csswg-drafts icon indicating copy to clipboard operation
csswg-drafts copied to clipboard

[css-align][css-inline] Support for aligning items to the center of the first line.

Open pomboverso opened this issue 2 years ago • 5 comments

Spec links:

align-items-property

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)

image

Proposal:

would it make sense having a property under flexbox, something like align-items: first-line-center for these cases?

codepen

image image

pomboverso avatar Jan 25 '24 05:01 pomboverso

I'm not sure I understand. Are you looking for align-self: first baseline?

fantasai avatar Feb 05 '24 23:02 fantasai

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: image

Multiline: image

This is the scenario that I'm trying to cover:

image

pomboverso avatar Feb 06 '24 14:02 pomboverso

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.

obrazek

adamkudrna avatar Feb 23 '24 17:02 adamkudrna

YES. This is such a common problem I run into. Huge +1 from me.

benface avatar Nov 07 '24 04:11 benface

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).

knowler avatar Sep 16 '26 16:09 knowler