Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda