When Webkit (Safari, Chrome) encounters an inline-block where...
line-height
height is specified...the inline-block element ignores the specified vertical-align
.
To help illustrate the problem, I have a small test case: http://arther.net/lab/webkit-vertical-align-test.html#test
Firefox 3.6, Opera 10.53, and IE7+ treat these inline-blocks like inline elements, and vertical align works as expected. Webkit browsers (and Opera 10.10) treat the inline-blocks in this situation like block-level elements, thus ignoring vertical-align
. So, who is right, and who is buggy?
I can see this going either way. On one hand, you can say that all inline elements — even inline-blocks — should position themselves properly within the containing line-box as per vertical-align
. On the other hand, inline elements usually define a single inline-box and don't have line-boxes of their own. Anything wrapping multiple line-boxes should be a block-level element. In that case, the inline-block should be treated as a block, which would thus ignore vertical-align
.
Given the current behavior, I figure that one of the following is true:
If anyone could provide some clarification on the issue and what the expected behavior should be, I would greatly appreciate it.
Even though the property says “text” align, it affects all elements inside the block-level element that are either inline or inline-block elements. The property only affects the content inside the element to which it is applied, and not the element itself.
To align things in the inline direction, use the properties which begin with justify- . Use justify-content to distribute space between grid tracks, and justify-items or justify-self to align items inside their grid area in the inline direction.
When the element to be centered is an inline element we use text-align center on its parent. When the element is a block level element we give it a width and set the left and right margins to a value of auto. With text-align: center in mind, most people look first to vertical-align in order to center things vertically.
This looks like a bug, since it works when the section takes only one line.
Chrome and Safari has a function where you can Report bugs to help their developers fix it.
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