-
-
Save HelgaZhizhka/444e640f769c9197d3b57c7bf35977f8 to your computer and use it in GitHub Desktop.
Pure CSS multiline text with ellipsis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* http://martinwolf.org/2013/01/29/pure-css-multiline-text-with-ellipsis/ */ | |
$font-size: 26px; | |
$line-height: 1.4; | |
$lines-to-show: 3; | |
h2 { | |
display: block; /* Fallback for non-webkit */ | |
display: -webkit-box; | |
max-width: 400px; | |
height: $font-size*$line-height*$lines-to-show; /* Fallback for non-webkit */ | |
margin: 0 auto; | |
font-size: $font-size; | |
line-height: $line-height; | |
-webkit-line-clamp: $lines-to-show; | |
-webkit-box-orient: vertical; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var ellipsisText = function (e, etc) {
var wordArray = e.innerHTML.split(" ");
while (e.scrollHeight > e.offsetHeight) {
wordArray.pop();
e.innerHTML = wordArray.join(" ") + (etc || "...");
}
};
[].forEach.call(document.querySelectorAll(".block-with-text"), function(elem) {
ellipsisText(elem);
});