Skip to content

Instantly share code, notes, and snippets.

@ChristianOellers
Last active June 10, 2024 07:42
Show Gist options
  • Save ChristianOellers/11aebc89d659fbe3a3ac7e9c54c656fa to your computer and use it in GitHub Desktop.
Save ChristianOellers/11aebc89d659fbe3a3ac7e9c54c656fa to your computer and use it in GitHub Desktop.
CSS line length cap (Specific number + Equal heights)
/**
* Example: Cap text at a specific line length.
* Especially useful for e.g. card/ tile layouts with different content but equal heights.
*/
.text-overflow {
--lines: 3;
height: calc(var(--lines) * 1.25rem);
font-size: 1rem;
line-height: 1.25rem;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: var(--lines);
-webkit-box-orient: vertical
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment