Skip to content

Instantly share code, notes, and snippets.

@isabellachen
Created January 23, 2020 12:24
Show Gist options
  • Save isabellachen/09b1746105c3e475daebe8f93acd14f3 to your computer and use it in GitHub Desktop.
Save isabellachen/09b1746105c3e475daebe8f93acd14f3 to your computer and use it in GitHub Desktop.
Content of nested flex child to constrain to calculated width of the child
<div class="flex-parent has-child">
<div class="flex-child long-and-truncated-with-child-corrected">
<h2>3. This is a long string that is OK to truncate please and thank you</h2>
</div>
<div class="flex-child short-and-fixed">
<div></div>
<div></div>
<div></div>
</div>
</div>
.flex-parent {
display: flex;
align-items: center;
padding: 10px;
margin: 30px 0;
}
h2 {
font-size: 1rem;
font-weight: normal;
}
.short-and-fixed {
white-space: nowrap;
> div {
width: 30px;
height: 30px;
border-radius: 10px;
background: lightgreen;
display: inline-block;
}
}
.long-and-truncated-with-child-corrected {
flex: 1;
min-width: 0; /* or some value */
h2 {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
body {
padding: 40px;
}
@isabellachen
Copy link
Author

image

@isabellachen
Copy link
Author

isabellachen commented Jan 23, 2020

With min-widht: 0
image
without min-width set to 0
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment