Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

319
Vistas
How to replace three dots added by -webkit-line-clamp with "read more" text

I am using -webkit-line-clamp to truncate text like the below example

.box {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;  
  overflow: hidden;
  width: 100px;
}
<div class="box">
  <p>Hey, don't cut me off like that. I want to speak my mind and don't appreciate being put into a box.</p>
</div>

Here I am getting 3 dots end of truncation, I want to have a "read more" link at the end of truncated text instead of .... Please let me know if this can be achieved through css or JS

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

How about this code? This code removes button when doesn't overflow.

var container = document.getElementsByClassName('container');
var i;
for (i=0;i<container.length;i++) {
  if (container[i].firstElementChild.scrollHeight<=container[i].firstElementChild.clientHeight) {
    container[i].lastElementChild.style.display = 'none';
  }
}
function more(x) {
  var box = x.parentElement.firstElementChild;
  if (!box.classList.contains('box-more')) {
    box.classList.add('box-more');
    x.innerHTML = "Close";
  }
  else {
    box.classList.remove('box-more');
    x.innerHTML = "Read More";
  }
}
.box {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;  
  overflow: hidden;
  width: 100px;
}
.box-more {
  -webkit-line-clamp: unset !important;
}
<div class="container">
  <div class="box">
    <p>Hey, don't cut me off like that. I want</p>
  </div>
  <button onclick="more(this)">Read More</button>
</div>
<div class="container">
  <div class="box">
    <p>Hey, don't cut me off like that. I want to speak my mind and don't appreciate being put into a box.</p>
  </div>
  <button onclick="more(this)">Read More</button>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda