Span Element With Display: Inline-flex Has Greater Height Than Sibling Span
Solution 1:
Your span
elements are, by default, inline-level elements.
The initial value of the vertical-align
property, which applies to inline-level elements, is baseline
. This allows browsers to provide a bit of space below elements to accommodate descenders.
When you apply display: inline-flex
to one of the spans you establish a flex formatting context. In this case, the children are blockified, meaning that the behavior is more like a block-level element.
Hence, the vertical-align
property no longer applies to span1, but it continues to apply to span2, which is why you still see the descender space.
From the spec (referring to the anonymous box which wraps the text and is the flex item):
The
display
value of a flex item is blockified: if the specifieddisplay
of an in-flow child of an element generating a flex container is an inline-level value, it computes to its block-level equivalent.
The simplest solution is to make the parent a flex container, which keeps your child elements inline by default, and allows you to set flex properties on both.
.container {
display: flex;
background-color: yellow;
border: 1px solid red;
}
.main {
border: 1px solid black;
}
<divclass="container"><spanclass="main">This is the flex container, height is 20px</span><spanclass="main">This is not the flex container, height is 19px</span></div>
More details:
Solution 2:
Seems to be an display:inline;
issue, changing it to display:inline-block;
fixes the height difference. Not sure how useful this is though...
body {
margin: 30px;
}
.container {
background-color: yellow;
border: 1px solid red;
}
.main {
border: 1px solid black;
display:inline-block;
}
.flex-cont {
display: inline-flex;
}
<divclass="container"><spanclass="main flex-cont">
This is the flex container, height is 20px
</span><spanclass="main">
This is not the flex container, height is 20px
</span></div>
Post a Comment for "Span Element With Display: Inline-flex Has Greater Height Than Sibling Span"