Skip to content

Instantly share code, notes, and snippets.

@electricg
Created February 2, 2018 17:16
Show Gist options
  • Save electricg/f8e403d33f4e2bba2af6e27b75035b29 to your computer and use it in GitHub Desktop.
Save electricg/f8e403d33f4e2bba2af6e27b75035b29 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/qoyejim
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
:root {
--lines: 3;
--line-height: 1.2em;
--label-height: 1em;
}
.divider {
margin: 50px 0;
}
.more__checkbox,
.more__label {
display: none;
}
@supports (-webkit-line-clamp: 3) {
.more {
outline: 1px solid blue;
position: relative;
overflow: hidden;
}
.more__label {
cursor: pointer;
background: #f00;
bottom: 100%;
display: block;
height: var(--label-height);
position: absolute;
top: calc(var(--line-height) * (var(--lines) + 0));
}
.more__label:after {
content: 'show more';
}
.text {
display: -webkit-box;
overflow : hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
background: pink;
line-height: var(--line-height);
margin-bottom: calc(var(--label-height) * 1);
margin-top: 0;
}
.text:after {
content: 'fake line';
display: block;
position: absolute;
}
.more__checkbox:checked ~ .text {
display: block;
overflow: visible;
}
.more__checkbox:checked ~ .more__label {
position: static;
}
.more__checkbox:checked ~ .more__label:after {
content: 'show less';
}
/* if we don't want to show the "show less" option */
/*.more__checkbox:checked ~ .more__label {
display: none;
}*/
}
/* this must go after the @supports to be able to overwrite it */
@media (min-width: 737px) {
.more__checkbox,
.more__label {
display: none;
}
.text {
display: block;
overflow: visible;
}
}
</style>
</head>
<body>
<div class="more">
<input type="checkbox" class="more__checkbox" id="more">
<p class="text">Start - <span>Lorem</span> <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Reprehenderit doloremque odit iure eveniet laborum provident voluptates, magni dolores illo nobis officiis adipisci eum cupiditate praesentium dolorum, placeat ratione illum asperiores in molestias beatae? Quam enim, accusamus minus officia quia vero ratione qui, voluptas numquam nemo magni cumque deleniti suscipit. Nulla pariatur tempore iusto error placeat inventore eum dolores ipsa debitis, officiis, quod hic quasi tenetur voluptatibus vel. Expedita fugiat animi totam dolorem libero non temporibus labore quaerat voluptatem fuga odio voluptatibus obcaecati quia delectus, vero quidem dignissimos veniam a odit? Possimus veniam rerum culpa a vel impedit ipsam. Cum, ex. - The End</p>
<label for="more" class="more__label"></label>
</div>
<hr class="divider">
<div class="more">
<input type="checkbox" class="more__checkbox" id="more1">
<p class="text">Start - <span>Lorem</span> <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Reprehenderit doloremque odit iure eveniet laborum provident voluptates. - The End</p>
<label for="more1" class="more__label"></label>
</div>
<script id="jsbin-source-css" type="text/css">:root {
--lines: 3;
--line-height: 1.2em;
--label-height: 1em;
}
.divider {
margin: 50px 0;
}
.more__checkbox,
.more__label {
display: none;
}
@supports (-webkit-line-clamp: 3) {
.more {
outline: 1px solid blue;
position: relative;
overflow: hidden;
}
.more__label {
cursor: pointer;
background: #f00;
bottom: 100%;
display: block;
height: var(--label-height);
position: absolute;
top: calc(var(--line-height) * (var(--lines) + 0));
}
.more__label:after {
content: 'show more';
}
.text {
display: -webkit-box;
overflow : hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
background: pink;
line-height: var(--line-height);
margin-bottom: calc(var(--label-height) * 1);
margin-top: 0;
}
.text:after {
content: 'fake line';
display: block;
position: absolute;
}
.more__checkbox:checked ~ .text {
display: block;
overflow: visible;
}
.more__checkbox:checked ~ .more__label {
position: static;
}
.more__checkbox:checked ~ .more__label:after {
content: 'show less';
}
/* if we don't want to show the "show less" option */
/*.more__checkbox:checked ~ .more__label {
display: none;
}*/
}
/* this must go after the @supports to be able to overwrite it */
@media (min-width: 737px) {
.more__checkbox,
.more__label {
display: none;
}
.text {
display: block;
overflow: visible;
}
}
</script>
</body>
</html>
:root {
--lines: 3;
--line-height: 1.2em;
--label-height: 1em;
}
.divider {
margin: 50px 0;
}
.more__checkbox,
.more__label {
display: none;
}
@supports (-webkit-line-clamp: 3) {
.more {
outline: 1px solid blue;
position: relative;
overflow: hidden;
}
.more__label {
cursor: pointer;
background: #f00;
bottom: 100%;
display: block;
height: var(--label-height);
position: absolute;
top: calc(var(--line-height) * (var(--lines) + 0));
}
.more__label:after {
content: 'show more';
}
.text {
display: -webkit-box;
overflow : hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
background: pink;
line-height: var(--line-height);
margin-bottom: calc(var(--label-height) * 1);
margin-top: 0;
}
.text:after {
content: 'fake line';
display: block;
position: absolute;
}
.more__checkbox:checked ~ .text {
display: block;
overflow: visible;
}
.more__checkbox:checked ~ .more__label {
position: static;
}
.more__checkbox:checked ~ .more__label:after {
content: 'show less';
}
/* if we don't want to show the "show less" option */
/*.more__checkbox:checked ~ .more__label {
display: none;
}*/
}
/* this must go after the @supports to be able to overwrite it */
@media (min-width: 737px) {
.more__checkbox,
.more__label {
display: none;
}
.text {
display: block;
overflow: visible;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment