When your website means business.

CSS | Type: PHPShow/hide text with row truncate

This avoids the mid-word break of the other show/hide snippet by selecting number of rows to show.

HTML
<div class="show-hide-text wrapper">
<a id="show-more" class="show-less" href="#show-less">Show less</a>
<a id="show-less" class="show-more" href="#show-more">Show more</a>
<p>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.</p>
</div>

CSS
.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;
}
.show-hide-text a {
  -webkit-box-ordinal-group: 3;
  -webkit-order: 2;
  -ms-flex-order: 2;
  order: 2;
}
.show-hide-text p {
  position: relative;
  overflow: hidden;
  max-height: 60px;
  line-height: 20px;
}
.show-hide-text p:after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100px;
  height: 20px;
  background: -moz-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%);
  background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%);
  background: -o-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%);
  background: -ms-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%);
  background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%);
}
@supports (-webkit-line-clamp: $rows) {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  .show-hide-text p:after {
    display: none;
  }
}
.show-less {
  display: none;
}
.show-less:target {
  display: block;
}
.show-less:target ~ p {
  display: block;
  max-height: 100%;
}
.show-less:target + a {
  display: none;
}
.wrapper {
  max-width: 300px;
  margin: 50px auto;
}
.wrapper p {
  font-size: 16px;
  line-height: 20px;
}

Reference Links

Menu
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Cookies Notice