Multiline Text truncation

This commit is contained in:
reverend 2020-12-27 16:01:44 +01:00
parent 8b4ba286d9
commit 2b938cf69e

View File

@ -1,66 +1,111 @@
@mixin RV-ContentCrop--bottom { @mixin RV-ContentCrop--bottom {
img { img {
object-position: botom; object-position: botom;
} }
} }
@mixin RV-ContentCrop--top { @mixin RV-ContentCrop--top {
img { img {
object-position: top; object-position: top;
} }
} }
@mixin RV-ContentCrop--right { @mixin RV-ContentCrop--right {
img { img {
object-position: right; object-position: right;
} }
} }
@mixin RV-ContentCrop--left { @mixin RV-ContentCrop--left {
img { img {
object-position: left; object-position: left;
} }
} }
@mixin RV-ContentCrop--center { @mixin RV-ContentCrop--center {
img { img {
object-position: center; object-position: center;
} }
} }
@mixin RV-ContentCrop{ @mixin RV-ContentCrop($-line-height: 1.1, $-prefix: '&') {
&,* {
overflow: hidden;
word-break: break-all;
}
img { // Heuristic, just to be safe
width: 100%; $-line-height: $-line-height * 1.1;
height: 100%; $-background-color: white;
object-fit: cover; display: block;
} overflow: hidden;
&--left { p {
@include RV-ContentCrop--left; overflow: hidden;
} display: block;
text-overflow: ellipsis;
padding: 0;
margin: 0;
line-height: #{$-line-height};
// Determining the max line count and caclulating the height
z-index: -20;
position: relative;
background-color: #{$-background-color};
height: floor(100% / $-line-height / 16) * $-line-height * 16;
}
&--center { &--fade {
@include RV-ContentCrop--center; &:after {
} background: linear-gradient(180deg, rgba(255, 255, 255, 0), #{$-background-color});
display: block;
content: ' ';
opacity: 0.8;
position: relative;
top: -25%;
width: 100%;
height: 25%;
z-index: -10;
}
}
&--top { &--ellipsis {
@include RV-ContentCrop--top; &:after {
} position: relative;
display: block;
bottom: 1.2em;
left: calc(100% - 3ch);
content: '...';
font-size: 1.2em;
min-width: 2em;
background-color: $-background-color;
padding: 0 2px;
}
}
&--bottom { img {
@include RV-ContentCrop--bottom; width: 100%;
} height: 100%;
object-fit: cover;
display: block;
}
&--center { #{$-prefix}--left {
@include RV-ContentCrop--center; @include RV-ContentCrop--left;
} }
#{$-prefix}--center {
@include RV-ContentCrop--center;
}
#{$-prefix}--top {
@include RV-ContentCrop--top;
}
#{$-prefix}--bottom {
@include RV-ContentCrop--bottom;
}
#{$-prefix}--center {
@include RV-ContentCrop--center;
}
} }
.RV-ContentCrop__Container { .RV-ContentCrop {
@include RV-ContentCrop; @include RV-ContentCrop;
} }