I went over the article from csstricks, https://css-tricks.com/flexbox-truncated-text/
My question how to make it work when the .flex-parent
has flex-direction: column;
property.
Thanks for help!
I went over the article from csstricks, https://css-tricks.com/flexbox-truncated-text/
My question how to make it work when the .flex-parent
has flex-direction: column;
property.
Thanks for help!
This really is just a matter of rearranging some properties, but naturally this answer depends on the projects needs.
Takeaways here are, if you want it to be a column, by nature every top-level element you include in the .flex-parent
, when it's set to column direction, will display as such. Therefore, there will be nothing to the right of it to truncate with.
So essentially, if you want top-level elements to be a column AND truncate content inside of it, then one way of accomplishing it is by including both of them in the same 'row' or .flex-child
. Then the row is where you could identify the justify and aligning properties.
.flex-parent {
display: flex;
flex-direction: column;
padding: 10px;
margin: 30px 0;
}
.flex-child {
display: flex;
justify-content: space-between;
align-items: center;
}
.long-and-truncated-with-child-corrected {
flex: 1;
min-width: 0; /* or some value */
}
.long-and-truncated-with-child-corrected h2 {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.short-and-fixed > div {
width: 30px;
height: 30px;
border-radius: 10px;
background: lightgreen;
display: inline-flex;
}
/*nonessentials*/
body {
padding: 40px;
}
h2 {
font-size: 1rem;
font-weight: normal;
}
.flex-parent {
background: rgba(0,0,0,0.1);
}
<div class="flex-parent">
<div class="flex-child long-and-truncated-with-child-corrected">
<h2>This is a <em>long string</em> that is OK to truncate please and thank you. Some more text to demonstrate, if the string is <b>REALLY</b> truncated</h2>
<div class="flex-child short-and-fixed">
<div></div>
<div></div>
<div></div>
</div>
</div>
</div>