nafashmn.ir
Tengo este código para acortar mi párrafo.
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
pero el problema es que este código hace todo en una sola línea. Entonces quiero ir con 3 líneas de texto… Busqué en Google al respecto y descubrí que tenemos un WebKit para eso.
webkit-line-clamp
pero no tengo ni idea de como usarlo y no funciona…
Rayees AC
Método – 1: Usando text-overflow: ellipsis;
span {
white-space: nowrap;
text-overflow: ellipsis;
width: 250px;
display: block;
overflow: hidden
}
<span>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.</span>
Método – 2: Uso -webkit-line-clamp
p {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
<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>
-
Hola amigo, gracias por tu ayuda. No quiero mostrar después de tres líneas (…)
– nafashmn.ir
12 de agosto de 2020 a las 12:46
-
Compruebe ahora @ nafashmn.ir Actualicé la respuesta. Tener dos métodos.
– Rayees AC
12 de agosto de 2020 a las 13:12
Ahmad
Solución sin flexbox
Establezca la altura del contenedor de texto y use webkit-line-clamp en consecuencia.
.line-clamp-3 {
display: block;
display: -webkit-box;
height: 50px;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
Solución con flexbox
También puede obtener ayuda de este enlace: https://css-tricks.com/flexbox-texto-truncado/
.flex-parent {
display: flex;
}
.short-and-fixed {
width: 30px;
height: 30px;
}
.long-and-truncated {
margin: 0 20px;
flex: 1;
min-width: 0;
}
.long-and-truncated span {
display: inline;
-webkit-line-clamp: 3;
text-overflow: ellipsis;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
word-wrap: break-word;
}
<div class="flex-parent">
<div class="flex-child short-and-fixed">
</div>
<div class="flex-child long-and-truncated">
<span>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.</span>
</div>
<div class="flex-child short-and-fixed">
</div>
</div>
-
Hola amigo, gracias por tu ayuda. Usar este código resuelve mi problema pero no deja tres puntos al final de la línea (…)
– nafashmn.ir
12 de agosto de 2020 a las 12:43
-
Utilice -webkit-line-clamp y height respectivamente para mostrar tres puntos (…). ¿Puedes compartir el contenedor div de texto?
– Ahmad
12 de agosto de 2020 a las 12:47
¡Hola! Agregue un fragmento de código que muestre su problema exacto.
– Debsmita Paul
12 de agosto de 2020 a las 12:09
la abrazadera de línea no es compatible con todos los navegadores.
– mttetc
12 de agosto de 2020 a las 12:17
@DebsmitaPaul Hola amigo… lee mi pregunta de nuevo 🙂
– nafashmn.ir
12 de agosto de 2020 a las 12:35
¿Puede dar más detalles sobre “no funciona”? ¿Cómo no funcionó webkit-line-clamp?
– Scratte
13 de agosto de 2020 a las 12:57