Esta traducción está incompleta. Por favor, ayuda a traducir este artículo del inglés.

La propiedad de CSS text-overflow determina como el contenido que se desborda y que no es mostrado, va a hacersele notar a los usuarios. Puede ser cortado, mostrar una elipsis ('', U+2026 Horizontal Ellipsis), o mostrar una cadena de texto personalizada.

La propiedad text-overflow no forza a que ocurra un desbordamiento. Para hacer que un texto desborde a su contenedor debes poner algunas otras propiedades de CSS. Por ejemplo:

overflow: hidden;
white-space: nowrap;

The text-overflow property only affects content that is overflowing a block container element in its inline progression direction (not text overflowing at the bottom of a box, for example).

Syntax

The text-overflow property may be specified using one or two values. If one value is given, it specifies overflow behavior for the end of the line (the right end for left-to-right text, the left end for right-to-left text). If two values are given, the first specifies overflow behavior for the left end of the line, and the second specifies it for the right end of the line.

Each value is specified as one of:

Values

clip
The default for this property. This keyword value will truncate the text at the limit of the content area, therefore the truncation can happen in the middle of a character. To clip at the transition between characters you can specify text-overflow as an empty string, if that is supported in your target browsers: text-overflow: '';.
ellipsis
This keyword value will display an ellipsis ('…', U+2026 Horizontal Ellipsis) to represent clipped text. The ellipsis is displayed inside the content area, decreasing the amount of text displayed. If there is not enough space to display the ellipsis, it is clipped.
<string>
The <string> to be used to represent clipped text. The string is displayed inside the content area, shortening the size of the displayed text. If there is not enough space to display the string itself, it is clipped.
fade
This keyword clips the overflowing inline content and applies a fade-out effect near the edge of the line box with complete transparency at the edge.
fade( <length> | <percentage> )
This function clips the overflowing inline content and applies a fade-out effect near the edge of the line box with complete transparency at the edge.
The argument determines the distance over which the fade effect is applied. The <percentage> is resolved against the width of the line box. Values lower than 0 are clipped to 0. Values greater than the width of the line box are clipped to the width of the line box.

Formal syntax

[ clip | ellipsis | <string> ]{1,2}

Examples

CSS

p {
  width: 200px;
  border: 1px solid;
  padding: 2px 5px;

  /* BOTH of the following are required for text-overflow */
  white-space: nowrap;
  overflow: hidden;
}

.overflow-visible {
  white-space: initial;
}

.overflow-clip {
  text-overflow: clip;
}

.overflow-ellipsis {
  text-overflow: ellipsis;
}

.overflow-string {
  /* Not supported in most browsers, 
     see the 'Browser compatibility' section below */
  text-overflow: " [..]"; 
}

HTML

<p class="overflow-visible">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<p class="overflow-clip">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<p class="overflow-ellipsis">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<p class="overflow-string">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>

Result

CSS value direction: ltr direction: rtl
Expected Result Live result Expected Result Live result
visible overflow 1234567890
1234567890
0987654321
1234567890
text-overflow: clip t-o_clip.png
123456
t-o_clip_rtl.png
1234567890
text-overflow: '' 12345
123456
54321
1234567890
text-overflow: ellipsis 1234…
1234567890
…4321
1234567890
text-overflow: '.' 1234.
1234567890
.4321
1234567890
text-overflow: clip clip 123456
1234567890
654321
1234567890
text-overflow: clip ellipsis 1234…
1234567890
6543…
1234567890
text-overflow: clip '.' 1234.
1234567890
6543.
1234567890
text-overflow: ellipsis clip …3456
1234567890
…4321
1234567890
text-overflow: ellipsis ellipsis …34…
1234567890
…43…
1234567890
text-overflow: ellipsis '.' …34.
1234567890
…43.
1234567890
text-overflow: ',' clip ,3456
1234567890
,4321
1234567890
text-overflow: ',' ellipsis ,34…
1234567890
,43…
1234567890
text-overflow: ',' '.' ,34.
1234567890
,53.
1234567890

Specifications

Specification Status Comment
CSS Basic User Interface Module Level 4
La definición de 'text-overflow' en esta especificación.
Working Draft Added the values <string> and fade and the fade() function
CSS Basic User Interface Module Level 3
La definición de 'text-overflow' en esta especificación.
Recommendation Initial definition

A previous version of this interface reached the Candidate Recommendation status. As some not-listed-at-risk features needed to be removed, the spec was demoted to the Working Draft level, explaining why browsers implemented this property unprefixed, though not at the CR state.

Valor inicialclip
Applies toblock container elements
Heredableno
Mediavisual
Valor calculadocomo se especifica
Animation typediscrete
Canonical orderel orden único no-ambigüo definido por la gramática formal

Browser compatibility

 

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Soporte básicoChrome Soporte completo 1Edge Soporte completo 12Firefox Soporte completo 7
Notas
Soporte completo 7
Notas
Notas Until Firefox 10, handling of text-overflow on blocks with inline overflow on both horizontal sides was incorrect. Before Firefox 10, if only one value was specified (such as text-overflow: ellipsis;), text was ellipsed on both sides of the block, instead of only the end edge based on the block's text direction.
IE Soporte completo 6
Soporte completo 6
Soporte completo 8
Prefijado
Prefijado Requiere de un prefijo de vendedor : -ms-
Opera Soporte completo 11
Soporte completo 11
Soporte completo 9
Prefijado
Prefijado Requiere de un prefijo de vendedor : -o-
Safari Soporte completo 1.3WebView Android Soporte completo SiChrome Android ? Edge Mobile Soporte completo SiFirefox Android Soporte completo 7
Notas
Soporte completo 7
Notas
Notas Until Firefox 10, handling of text-overflow on blocks with inline overflow on both horizontal sides was incorrect. Before Firefox 10, if only one value was specified (such as text-overflow: ellipsis;), text was ellipsed on both sides of the block, instead of only the end edge based on the block's text direction.
Opera Android Soporte completo SiSafari iOS Soporte completo SiSamsung Internet Android ?
Two-value syntax
Experimental
Chrome Sin soporte NoEdge Sin soporte NoFirefox Soporte completo 9IE Sin soporte NoOpera Sin soporte NoSafari Sin soporte NoWebView Android Sin soporte NoChrome Android ? Edge Mobile Sin soporte NoFirefox Android Soporte completo 9Opera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
<string>
Experimental
Chrome Sin soporte NoEdge Sin soporte NoFirefox Soporte completo 9IE Sin soporte NoOpera Sin soporte NoSafari Sin soporte NoWebView Android Sin soporte NoChrome Android ? Edge Mobile Sin soporte NoFirefox Android Soporte completo 9Opera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
fade
Experimental
Chrome Sin soporte NoEdge Sin soporte NoFirefox Sin soporte NoIE Sin soporte NoOpera Sin soporte NoSafari Sin soporte NoWebView Android Sin soporte NoChrome Android ? Edge Mobile Sin soporte NoFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No
fade()
Experimental
Chrome Sin soporte NoEdge Sin soporte NoFirefox Sin soporte NoIE Sin soporte NoOpera Sin soporte NoSafari Sin soporte NoWebView Android Sin soporte NoChrome Android ? Edge Mobile Sin soporte NoFirefox Android Sin soporte NoOpera Android Sin soporte NoSafari iOS Sin soporte NoSamsung Internet Android Sin soporte No

Leyenda

Soporte completo  
Soporte completo
Sin soporte  
Sin soporte
Compatibility unknown  
Compatibility unknown
Experimental. Esperar que el comportamiento cambie en el futuro.
Experimental. Esperar que el comportamiento cambie en el futuro.
Ver notas de implementación.
Ver notas de implementación.
Requiere de un prefijo de proveedor o un de nombre diferente para su uso.
Requiere de un prefijo de proveedor o un de nombre diferente para su uso.

 

See also

Etiquetas y colaboradores del documento

Colaboradores en esta página: camilobuitrago
Última actualización por: camilobuitrago,