Tecnologías XML / CSS / Sitios web avanzados con CSS / Efectos de texto y cascada / Espaciado horizontal y vertical / Las propiedades letter-spacing y word-spacing

(Extracto de «CSS − Sitios web avanzados con Cascading Stylesheets» de Rachel Andrew & Dan Shafer)

La propiedad letter-spacing define el espacio entre caracteres, también llamado interletraje. CSS admite valores relativos y absolutos; el predeterminado es normal. La figura siguiente muestra claramente el efecto de letter-spacing.

  Interletraje modificado con letter-spacing

Figura: interletraje modificado con letter-spacing.

Este HTML produce la página mostrada:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Modifzierte Laufweite einer Schrift mit letter-spacing</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <style type="text/css">
    body {
      background-color: #FFFFFF;
      font-family: helvetica, arial, sans-serif;
    }
    p {
      font-size: 16pt;
    }
    .luftig {
      letter-spacing: 0.5em;
    }
  </style>
</head>
<body>
  <p class="luftig">Alle Absätze mit der zugewiesenen Klasse 'luftig' auf dieser Seite sind mit dem Wert 0.5em für die Laufweite der Schrift formatiert. Man kann den Effekt, den diese Zuweisung erzeugt, deutlich erkennen.</p>
  <p>Dieser Absatz hingegen ist keine Instanz der Klasse 'luftig' und wird deswegen in der normalen Laufweite der Schrift angezeigt.</p>
</body>
</html>

La propiedad letter-spacing aumenta el espacio entre letras y palabras. Los navegadores consideran las palabras grupos de letras separados por espacios, también afectados por el interletraje.

La propiedad letter-spacing también admite valores negativos para cerrar el interletraje. Es útil para encabezados cuyas letras, sobre todo en las familias sans-serif y monospace, están demasiado separadas por defecto. La figura compara dos encabezados. El primero no tiene letter-spacing explícito. Los huecos junto a «i», «l» y «t» son grandes. El segundo utiliza un valor negativo de letter-spacing para compactar el texto.

Cerrar el interletraje con letter-spacing

Figura: cerrar el interletraje con letter-spacing.

Este es el HTML. Observe la clase zusammengerueckt asignada al segundo encabezado h1.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Verringerung der Laufweite mit letter-spacing</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <style type="text/css">
    body {
      background-color: #FFFFFF;
      font-family: helvetica, arial, sans-serif;
    }
    h1 {
      font-family: Courier, "Courier New", monospace;
    }
    .zusammengerueckt {
      letter-spacing: -0.08em;
    }
  </style>
</head>
<body>
  <h1>Diese Überschrift wirkt etwas zu weit auseinander gezogen</h1>
  <h1 class="zusammengerueckt">So sieht sie schon besser aus!</h1>
</body>
</html>

Basta una pequeña reducción. Para familiarizarse con el interletraje, experimente con letter-spacing con distintas fuentes y tamaños. Esta potente propiedad mejora fácilmente un diseño y crea efectos interesantes.

Efecto gráfico con letter-spacing

Figura: efecto gráfico con letter-spacing.

Este efecto procede únicamente del interletraje, sin editor gráfico.

Este es el código de la página:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Gestalterischer Effekt mit letter-spacing</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <style type="text/css">
    body {
      background-color: #FFFFFF;
      font-family: helvetica, arial, sans-serif;
    }
    .seitentitel {
      font-family: Courier, 'Courier New', monospace;
      font-size: 18pt;
      letter-spacing: 0.7em;
      text-transform: lowercase;
    }
  </style>
</head>
<body>
  <h2 class="seitentitel">Klaus Mustermanns extravagante Webseite</h2>
  <p>Die gedehnte Überschrift sieht fast aus wie ein Logo für Klaus Mustermanns Webseite, dabei wurde sie ohne jegliche grafische Hilfsmittel erstellt.</p>
</body>
</html>

La propiedad word-spacing ajusta solo el espacio entre palabras, pero se desaconseja por dos razones:

Primero, no todos los navegadores la admiten. Internet Explorer anterior a 6 para Windows o 5 para Macintosh no admite word-spacing, ni Netscape Navigator anterior a 6. IE 5 para Macintosh puede solapar palabras. Solo las versiones más recientes de Internet Explorer para Windows, Netscape Navigator, Opera y Mozilla procesan word-spacing correctamente, aunque existe desde CSS1 en la especificación W3C.

Espacio entre palabras con word-spacing

Figura: espacio entre palabras con word-spacing.

Segundo, combinar word-spacing con text-align: justify puede producir efectos imprevisibles en cualquier navegador. No los combine.

La figura muestra word-spacing con el valor 1em en una frase larga. Este es el HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Wortabstaende mit der Eigenschaft word-spacing</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <style type="text/css">
    body {
      background-color: #FFFFFF;
      font-family: helvetica, arial, sans-serif;
    }
    .weit {
      word-spacing: 1em;
      font-size: 1.5em;
    }
  </style>
</head>
<body>
  <p class="weit">Schauen wir doch mal, was mit dem Abstand zwischen den Wörtern geschieht, wenn wir einem Absatz die Klasse "weit" zuweisen. In dieser Klasse bekommt die Eigenschaft <code>word-spacing</code> den Wert 1em.</p>
</body>
</html>

  

<< atrás

siguiente >>

 

 

 

volver arriba