html - How to set width based on content length using flex -


i'm trying make width of each item based on content have far set width way available spaces. flex: 0 0 auto not seem trick. doing wrong?

goal have width based on content size.

[hello] [hello world] 

currently

[hello                   ] [hello world             ] 

https://jsfiddle.net/v6cgljbd/8/

<span class='box'>   <span class='item'>hello</span>   <span class='item'>hello world</span>   <span class='item'>hello looooong text</span> </span>  .box {   height: 200px;   width: auto;   border: 1px solid red;   display: flex;   flex-direction: column; }  .item {   background-color: gray;   flex: 0 0 auto;   width: auto; } 

you need add align-items: flex-start on flex-container. when use flex-direction: column on parent element, flex property on child elements control height not width.

.box {    height: 200px;    border: 1px solid red;    display: flex;    flex-direction: column;    align-items: flex-start;  }    .item {    background-color: gray;  }
<span class='box'>    <span class='item'>hello</span>    <span class='item'>hello world</span>    <span class='item'>hello looooong text</span>  </span>


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -