File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ $font-size-line-height-difference : 4px !default ;
2+
3+ // Returns the computed line-height the caller should have.
4+ //
5+ // @param {Number | String} $difference - Difference from line-height to font-size. Should be positive.
6+ //
7+ // @return {String}
8+ //
9+ @function line-height ($difference : $font-size-line-height-difference ) {
10+ @return calc (1em + #{$difference } );
11+ }
12+
13+ // Truncates the element based on amount of lines and line-height.
14+ // Do not override the CSS properties that this mixin adds!
15+ //
16+ // Usage:
17+ // p.truncate-3 {
18+ // font-size: 16px;
19+ // @include truncate(3);
20+ // }
21+ //
22+ // @param {Number} $lines - Amount of lines that should be shown.
23+ // @param {Number | String} $lineHeight - Line-height that will be used for the calculation of max-height.
24+ // Should be greater than or equal font-size.
25+ //
26+ // @throws 'Parameter "lines" needs to be zero or a positive integer!'
27+ //
28+ @mixin truncate ($lines : 1 , $lineHeight : line-height ()) {
29+ @if type-of ($lines ) != ' number'
30+ or not unitless ($lines )
31+ or $lines < 0
32+ or round ($lines ) != $lines {
33+ @error ' Parameter "lines" needs to be zero or a positive integer!' ;
34+ }
35+ display : block ;
36+ overflow : hidden ;
37+ box-sizing : content-box ;
38+ padding-top : 0 ;
39+ padding-bottom : 0 ;
40+ line-height : $lineHeight ;
41+ max-height : calc (#{$lineHeight } * #{$lines } );
42+ }
You can’t perform that action at this time.
0 commit comments