Skip to content

Instantly share code, notes, and snippets.

@nkpgardose
Last active August 29, 2015 14:24
Show Gist options
  • Save nkpgardose/d1f942ba76b1918629be to your computer and use it in GitHub Desktop.
Save nkpgardose/d1f942ba76b1918629be to your computer and use it in GitHub Desktop.
Clamping is the king. Ellipsis gaming
.clamp {
overflow: hidden;
}
.clamp.is-active {
position: relative;
height: 7em;
}
.clamp.is-active:after {
content: "";
text-align: right;
position: absolute;
bottom: 0;
right: 0;
height: 1.2em;
background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
}
@supports (-webkit-line-clamp: 4) {
.clamp.is-active{
display: -webkit-box;
-webkit-line-clamp: 4;
-webkit-box-orient: vertical;
max-height: 7em;
height: auto;
}
.clamp.is-active:after {
display: none;
}
}
$(document).on('click','.read-more', function(e) {
e.stopPropagation();
e.preventDefault();
$(this).parent().find('.clamp').toggleClass('is-active');
});
<div class="clamp is-active">
<p>...</p>
<p>...</p>
</div>
<p class="clamp is-active">...</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment