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

147
Visualizações
How to make insertion into contentEditable paragraph bound by its size?

I need an editable one line paragraph such that the text inserted into it must not overflow its size.

I'm currently using CSS to try to hide the overflow and also to avoid multiple lines (by not displaying the paragraph's children).

However, ideally I need the text inserted into the paragraph to be "cut" as soon as it would overflow.

This is my code so far (also in JSFiddle):

div
{
  width: 50vw;
  height: 50vh;
  margin: 10px auto;
  background-color: gray;
}

p
{
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 25%;
  background-color: brown;
  text-align: center;
  
  white-space: nowrap;
  overflow-x: hidden;
}

/* Avoiding multiple lines */
p *
{
  display: none;
}
<div>
  <p contentEditable="true">
    Edit me! Unfortunally I can be overflowed... :(
  </p>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use word-break: keep-all; property in this case

div {
  width: 50vw;
  height: 50vh;
  margin: 10px auto;
  background-color: gray;
}

p {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 25%;
  background-color: brown;
  text-align: center;
  word-break: keep-all;
  white-space: normal;
}

p * {
  display: none;
}
<div>
  <p contentEditable="true">
    Edit me! Unfortunally I can be overflowed... :(
  </p>
</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