From d91eb83864753bf73725a4abe8e0df64442c51c9 Mon Sep 17 00:00:00 2001 From: Vagelis Tzortzis Date: Fri, 28 Oct 2016 12:50:20 +0300 Subject: [PATCH 1/2] Add new component: show/hide truncated text A pure css component with :target, row truncation via line-clamp and flex in order to create together a fully functional show/hide toggle for truncated text(in specific rows that we assign with the help of a mixin) --- .../show_hide_truncated_text/caniuse.txt | 3 ++ .../show_hide_truncated_text/codepen.html | 1 + .../show_hide_truncated_text/html.html | 7 ++++ .../show_hide_truncated_text/resources.txt | 1 + .../show_hide_truncated_text/scss.scss | 35 +++++++++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 comparisons/components/show_hide_truncated_text/caniuse.txt create mode 100644 comparisons/components/show_hide_truncated_text/codepen.html create mode 100644 comparisons/components/show_hide_truncated_text/html.html create mode 100644 comparisons/components/show_hide_truncated_text/resources.txt create mode 100644 comparisons/components/show_hide_truncated_text/scss.scss diff --git a/comparisons/components/show_hide_truncated_text/caniuse.txt b/comparisons/components/show_hide_truncated_text/caniuse.txt new file mode 100644 index 0000000..e23a0c0 --- /dev/null +++ b/comparisons/components/show_hide_truncated_text/caniuse.txt @@ -0,0 +1,3 @@ +Target: http://caniuse.com/#feat=css-sel3 +line-camp: http://caniuse.com/#search=line-clamp +Flex: http://caniuse.com/#search=flex diff --git a/comparisons/components/show_hide_truncated_text/codepen.html b/comparisons/components/show_hide_truncated_text/codepen.html new file mode 100644 index 0000000..26f2a30 --- /dev/null +++ b/comparisons/components/show_hide_truncated_text/codepen.html @@ -0,0 +1 @@ +

See the Pen show/hide text with row truncate by Vangel Tzo (@srekoble) on CodePen.

diff --git a/comparisons/components/show_hide_truncated_text/html.html b/comparisons/components/show_hide_truncated_text/html.html new file mode 100644 index 0000000..16b70d0 --- /dev/null +++ b/comparisons/components/show_hide_truncated_text/html.html @@ -0,0 +1,7 @@ +
+ Show less + Show more +

+ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. +

+
diff --git a/comparisons/components/show_hide_truncated_text/resources.txt b/comparisons/components/show_hide_truncated_text/resources.txt new file mode 100644 index 0000000..ecfabc3 --- /dev/null +++ b/comparisons/components/show_hide_truncated_text/resources.txt @@ -0,0 +1 @@ +Vangel Tzo show/hide text: http://codepen.io/srekoble/pen/WGBzZa diff --git a/comparisons/components/show_hide_truncated_text/scss.scss b/comparisons/components/show_hide_truncated_text/scss.scss new file mode 100644 index 0000000..e596839 --- /dev/null +++ b/comparisons/components/show_hide_truncated_text/scss.scss @@ -0,0 +1,35 @@ +@mixin truncate($rows) { + overflow: hidden; + display: -webkit-box; + -webkit-line-clamp: $rows; + -webkit-box-orient: vertical; +} + +.show-hide-text { + display: flex; + flex-wrap: wrap; + + a { + order: 2; + } + + p { + @include truncate(3); + } +} + +.show-less { + display: none; + + &:target { + display: block; + + ~ p { + display: block; + } + + + a { + display: none; + } + } +} From 19cd86e4525bd523fdad0b8e5d9b6b7846a4fe56 Mon Sep 17 00:00:00 2001 From: Vagelis Tzortzis Date: Wed, 2 Nov 2016 10:20:20 +0200 Subject: [PATCH 2/2] Add needed prefixes * Add prefixes for flex properties * Update truncate mixin to provide fallback for firefox with a usage of a gradient instead of line-clamp --- .../show_hide_truncated_text/scss.scss | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/comparisons/components/show_hide_truncated_text/scss.scss b/comparisons/components/show_hide_truncated_text/scss.scss index e596839..92c9a93 100644 --- a/comparisons/components/show_hide_truncated_text/scss.scss +++ b/comparisons/components/show_hide_truncated_text/scss.scss @@ -1,20 +1,59 @@ -@mixin truncate($rows) { +@mixin row-truncate($rows, $line-height, $background: '') { + position: relative; overflow: hidden; - display: -webkit-box; - -webkit-line-clamp: $rows; - -webkit-box-orient: vertical; + max-height: $line-height * $rows; + line-height: $line-height; + + &:after { + content: ""; + position: absolute; + right: 0; + bottom: 0; + width: 100px; + height: $line-height; + + @if $background != '' { + background: -moz-linear-gradient(left, rgba($background, 0) 0%, rgba($background, 1) 100%); + background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba($background, 0)), color-stop(100%, rgba($background, 1))); + background: -webkit-linear-gradient(left, rgba($background, 0) 0%,rgba($background, 1) 100%); + background: -o-linear-gradient(left, rgba($background, 0) 0%, rgba($background, 1) 100%); + background: -ms-linear-gradient(left, rgba($background, 0) 0%, rgba($background, 1) 100%); + background: linear-gradient(to right, rgba($background, 0) 0%, rgba($background, 1) 100%); + } + } + + // If supports line-clamp then add an ellipsis overflow and hide the gradient + // This will work in Chrome and Opera, otherwise a gradient will gradually hide the text. + + @supports (-webkit-line-clamp: $rows) { + display: -webkit-box; + -webkit-line-clamp: $rows; + -webkit-box-orient: vertical; + + &:after { + display: none; + } + } } .show-hide-text { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; display: flex; + -webkit-flex-wrap: wrap; + -ms-flex-wrap: wrap; flex-wrap: wrap; a { + -webkit-box-ordinal-group: 3; + -webkit-order: 2; + -ms-flex-order: 2; order: 2; } p { - @include truncate(3); + @include truncate(3, 20px, #fff); // rows, line-height, gradient fallback } } @@ -26,6 +65,11 @@ ~ p { display: block; + max-height: 100%; + + &:after { + display: none; + } } + a {