Skip to content

Instantly share code, notes, and snippets.

@Caellian
Last active August 7, 2023 17:03
Show Gist options
  • Save Caellian/9901c543943f0f03f63257c1ad1ba2b0 to your computer and use it in GitHub Desktop.
Save Caellian/9901c543943f0f03f63257c1ad1ba2b0 to your computer and use it in GitHub Desktop.
Text ellipsis and line clamping
p {
display: inline-block; // fallback for CSS4
display: -webkit-inline-box; // specialized renderer supported by all major browsers
-webkit-box-orient: vertical; // Required by FF for -webkit-line-clamp
-webkit-line-clamp: 1;
line-clamp: 1; // Forward CSS4 support
font-size: var(--size);
line-height: calc(var(--size) * 1.2); // leave wiggle room for descending characters (e.g. jy...)
overflow: hidden; // required for ellipsis
max-height: 1.2em; // based on font-size; same as above multiplier
text-overflow: ellipsis;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment