Text Replacement Techniques in HTML / CSS

Monday, June 23, 2008

The proper way to enter titles in graphics on a Web page is to replace using style sheets (see Progressive Enhancement in Accessibility and Usability: unobtrusive Javascript). This technique allows you to make the contents of the site irrespective graphics display imposed by sheets of styles. In addition, crawlers and spiders will have a correct reading HTML methods ignoring the replacement bid to end graphics. Insert a picture directly (TAG img it makes the title inaccessible to ordinary readers ASCII (crawlers, spiders, blog plugin, screen-reader, etc ...).
Another advantage is not to underestimate the ability to upload a style sheet in relation to language, making this the site also located at the pictures.
The technique of using CSS replace operation can be applied only to Web sites already online, where the HTML, for various reasons, it is not altered. The necessary and sufficient so that we can apply the technique of substitution is to have access to a unique title / text to replace. For example, if we have a condition like this:

HTML:
  1. Questo è il titolo numero uno </h1> <h1 id ="titolo_uno"> This is the number one title </ h1>

Thanks all'attributo id in the TAG H1 a possible CSS code would be:

CSS:
  1. h1 (# titolo_uno
  2. text-indent:-1000000px;
  3. ;width:100px;height:30px; display: block; width: 100px; height: 30px;
  4. ( images/titolo-in-grafica.gif ) no-repeat ; background: url (images / title-in-grafica.gif) no-repeat;
  5. )

Not having to dial a unique, like id of the previous case, things obviously are more complicated, and each case must be examined separately, trying to recover uniqueness in the HTML DOM tree.

If instead you write the HTML code, council this syntax, which guarantees a good taggatura:

HTML:
  1. =”Questo è il titolo numero uno” > <span> Questo è il titolo numero uno </span> </h1> <h1 id ="titolo_uno" title ="Questo is the title number uno"> <span> This is the number one title </ span> </ h1>

And its related CSS:

CSS:
  1. } # titolo_uno span h1 (display: none)
  2. h1 (# titolo_uno
  3. ;width:100px;height:30px; display: block; width: 100px; height: 30px;
  4. ( images/titolo-in-grafica.gif ) no-repeat ; background: url (images / title-in-grafica.gif) no-repeat;
  5. )

This prevents the text-indent:-1000000px making everything cleaner, despite the addition of the span The text itself disappears through the span but remains the title above the title graphics.
This procedure has the great advantage of not requiring Javascript to be used, making it simple and easy to apply also for the less experienced.

Related Post

4 comments to: "Text Replacement Techniques in HTML / CSS"

  1. getAvatar 1.0 Tuesday 24 June, 2008 at 11:03 a.m.
    Angelo said:

    Use the text-indent so I do not think it completely right, but with the second solution solves everything .. I like it, is a good technique .. keep in the account for future work!

    Answer Quote
  2. getAvatar 1.0 Tuesday 24 June, 2008 at 11:08 a.m.
    Giovambattista Fazioli said:

    @ Angelo: I agree, the text-indent normally is a "piece" when you can not write an HTML better. The second, however, I always use when I have to do with titles that "may" be replaced by graphic below.
    In the coming days will present another very interesting technique to replace text with graphics ... then I say it is "nice" as I found myself :)

    Answer Quote
  3. getAvatar 1.0 Tuesday 24 June, 2008 at 11:12 a.m.
    Angelo said:

    not fail! ;)

    Answer Quote
  4. getAvatar 1.0 Wednesday 25 June, 2008 at 10:39 a.m.
    Text Replacement Techniques in Flash | Undolog.com said:

    [...] Text Replacement I am presenting today is in some respects, really interesting. Unlike the classic image to replace through CSS, this technique uses a flash to override the titles of our site. Despite being a [...]

Leave a comment

TAG XHTML <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <a <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Use <pre> to enclose code