JSFiddle - React, Tailwind, and code Playground

by HDL52

HTML

<div class="card">
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Inventore consectetur temporibus quae aliquam nobis nam accusantium,
    minima quam iste magnam autem neque laborum nulla esse cupiditate modi impedit sapiente vero?</p>
</div>

CSS

:root {
  --base: 1.35;
  /* Handy multiplier for consistency across elements */
  --background: hsl(0 0% 0% / 1);
}

body {
  background-image: radial-gradient(circle at top, #222, var(--background));
  display: grid;
  height: 100vh;
  place-items: center;
}

.card {
  background-color: var(--background);
  border: 2px solid lch(100% 0 0 / 0.25);
  border-radius: 16px;
  color: lch(100% 0 0 / 0.85);
  font-size: calc(1rem * var(--base));
  line-height: var(--base);
  max-width: 35ch;
  padding: calc(1rem * var(--base));
}

.card p {
  max-height: calc(4rem * var(--base));
  /* Set a cut-off point for the content */
  overflow: hidden;
  /* Cut off the content */
  position: relative;
  /* needed for :after */
}

.card p:after {
  content: "";
  /* Change number here */
  background: linear-gradient(to right, transparent, var(--background) 85%);
  display: block;
  height: calc(1rem * var(--base) + 1px);
  position: absolute;
  inset-block-end: 0;
  pointer-events: none;
  width: 100%;
}

JavaScript

// https://css-tricks.com/recreating-mdns-truncated-text-effect/