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

600
Vistas
Aplicar sangría a la primera línea de un párrafo, pero solo si ocupa varias líneas

Me gustaría sangrar la primera línea de los párrafos (exactamente lo que hace la propiedad CSS text-indent ), pero solo para aquellos párrafos que ocupan varias líneas. Si un párrafo cabe en una sola línea, no quiero que tenga sangría.

¿Es posible lograr un resultado similar?

 p { text-indent: 20px; max-width: 350px; }
 <p>This is a pretty long paragraph which spans over a few lines. For that reason I wish its first line to be indented (as it should be).</p> <p>These are short paragraphs.</p> <p>I don't want them indented.</p> <p>Unless they take multiple lines.</p>

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Aquí hay una idea hacky que requiere un envoltorio adicional:

 p { max-width: 350px; line-height:1.2em; /* height of one line */ } .e { display:flex; /* a flex container to be able to use 100% in the height*/ } /* a pseudo element to create the indentation*/ .ep:before { content:""; float:left; width:20px; /* 0px if 100% (height of p) is less or equal to 1.2em (one line) 1px if 100% is bigger than one line */ height:clamp(0px,100% - 1.2em,1px) }
 <div class="e"><p>This is a pretty long paragraph which spans over a few lines. For that reason I wish its first line to be indented (as it should be).</p></div> <div class="e"><p>These are short paragraphs.</p></div> <div class="e"><p>I don't want them indented.</p></div> <div class="e"><p>Unless they take multiple lines.</p></div>

Una demostración interactiva donde puedes cambiar el tamaño para ver la magia en juego:

 p { line-height:1.2em; /* height of one line */ } .e { display:flex; /* a flex container to be able to use 100% in the height*/ overflow:hidden; border:1px solid; resize:horizontal; width: 350px; } /* a pseudo element to create the indentation*/ .ep:before { content:""; float:left; width:20px; /* 0px if 100% (height of p) is less or equal to 1.2em (one line) 1px if 100% is bigger than one line */ height:clamp(0px,100% - 1.2em,1px) }
 <div class="e"><p>This is a pretty long paragraph which spans over a few lines. For that reason I wish its first line to be indented (as it should be).</p></div>

over 4 years ago · Santiago Trujillo 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