I
I
Ilya2018-02-15 23:54:58
css
Ilya, 2018-02-15 23:54:58

Flex span auto width if line wraps?

If the span in flex wraps to the second line, the width becomes 100%, how do I set the width to auto?
Example :

<div>
  <span>1234567890 1234</span>
</div>

div{
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: red;
}
span{
  background: green;
}

Result:
4AkYaOHMpREdmq.jpg
And you need the span to be not the full width, but the size of the text and the text itself was on the left side, like this:
nAywoXCX03MxmZ.jpg
But without setting the width of the span in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Ankhena, 2018-02-16
@Mr_Epic

Like this https://jsfiddle.net/wx6mg2mj/
But it's not clear why flex

I
Igor Myasnikov, 2018-02-16
@pilium

Wrap span with another div like
Example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question