<span> element refuses to go inline in flexbox

I'm assuming that your .option-text has display:flex (otherwise setting flex-direction on it would make no sense). Given that, the behavior you describe is actually required by the flexbox spec -- children of a flex container are forced to have a block-flavored display type.

Specifically, the spec says:

each child of a flex container becomes a flex item [...] The computed ‘display’ of a flex item is determined by applying the table in CSS 2.1 Chapter 9.7

Source: http://www.w3.org/TR/css3-flexbox/#flex-items

That table it refers to, from CSS 2.1, basically converts non-blocks to blocks.

If you don't want this behavior, just wrap your <span> in a <div>, and then the <div> will play the role of the flex item so that the <span> can keep its display type.


The answer given by @dholbert is naturally correct. However, there is another solution that worked for me for the browsers Chrome, Edge, and Firefox. You have to set the display CSS attribute to contents.

In your case, it is:

span.time-pretext {
    display: contents;
}

Or for a more general solution:

CSS:

span.flex-inline {
    display: contents;
}

HTML:

<a class="option-container option-edit-time" href="#">
  <div class="option-icon"><canvas id="time-canvas" width="128" height="128"></canvas></div>
  <div class="option-text"><span class="flex-inline time-pretext">I have</span>60 minutes</div>
</a>

Tags:

Html

Css

Flexbox