Here are the eyes with align-items: center
property. They are OK for one-line text and FAIL for multiline text:
Here are the eyes with align-items: baseline
(or flex-start
). They are better for multiline text but not ideal for all of them because I want to align the eye to the center of first line of the text:
What I’m trying to achieve is this:
See how the eye image is centered at the first line of the text?
Is it possible to do it elegantly with flexbox properties, without using padding or margin?
(This is a simplified example. In the real problem I don’t want to introduce padding because it will affect other items.)
Here is jsfiddle to play with: http://jsfiddle.net/sqp1wdap/
Use line-height for vertical centering with a fixed height To vertically center a single line of text or an icon within its container, we can use the line-height property. This property controls the height of a line in a run of text and adds an equal amount of space above and below the line-box of inline elements.
The vertical-align attribute is for inline elements only. It will have no effect on block level elements, like a div. Also text-top only moves the text to the top of the current font size. If you would like to vertically align an inline element to the top just use this.
I found the solution: http://jsfiddle.net/sqp1wdap/3/
flex-start
line-height
for text same as Eye height Here is the edited code:
.LegendItem_Eye { width: $slotWidth; display: flex; justify-content: center; align-items: flex-start; // ← edit (1) background: #eee; } .LegendItem_Text { padding: 0 3px; flex: 1; align-self: flex-start; // ← edit (1) background: #eaa; line-height: $fontSize; // ← edit (2) }
And here is how it looks like:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With