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

161
Vistas
Add an early ellipsis if child is wider than parent

I am using text-overflow: ellipsis; for overflowing text of a child element.

In the case that the child element is wider than the parent element, the ellipsis cannot be seen.

input {
  border: 1px solid black;
  text-overflow: ellipsis;
  width: 100px;
}

div {
  border: 1px dotted black;
  width: 80px;
  overflow: clip;
}

/* Simulate overflow: clip; for Safari */
div > input {
  clip-path: polygon(0 0, 80px 0, 80px 100%, 0 100%);
}
<input type="text">
<div><input type="text"></div>

Current behaviour:

enter image description here

Desired behaviour:

enter image description here

I can't artificially make the child's width property smaller in my case, because another CSS rule depends on it (for min-content of an input element, considered contentless unless width specified)

Unfortunately there's no overflow: ellipsis; and adding text-overflow: ellipsis; on the parent doesn't fix it.

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

0

you can't make the input wider that it's div container and choose where the ellipsis starts in the input .. you can make the input 100px wide and the div 80px and it works but you can't see the result because the div is preventing the rest of the input from showing, and it doesn't make sense to do it in the first place.

just make the overflow of the input is hidden and the white-space: nowrap and make the width of the input same as it's container and it works just fine

input {
  border: 1px solid black;
  text-overflow: ellipsis;
  width: 100px;
  overflow: hidden;
  white-space: nowrap;
}

div {
  border: 1px dotted black;
  width: 80px;
  overflow: clip;
}

/* Simulate overflow: clip; for Safari */
div > input {
  clip-path: polygon(0 0, 80px 0, 80px 100%, 0 100%);
  width: 100%;    
}
<input type="text">
<div><input type="text"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Why Not Define classes to them so it will not affect other elements?

Like in the Example Below: I Have defined input-1 and class-1 as the class for different inputs

.input-1 {
  border: 1px solid black;
  text-overflow: ellipsis;
  width: 100px;
}

.class-2 {
  border: 1px dotted black;
  width: 80px;
  overflow: clip;
  text-overflow: ellipsis;
}

/* Simulate overflow: clip; for Safari */
div > input {
  clip-path: polygon(0 0, 80px 0, 80px 100%, 0 100%);
}
<input type="text" class="input-1">
<div><input type="text" class="class-2"></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