On Tue, Dec 20, 2011 at 4:38 AM, Grant Bailey
<[email protected]> wrote:
> Hello,
>
> I was wondering if anyone could clarify whether it is possible to style an
> attribute. I realise this sounds odd, so allow me to explain what I wish to
> do.
>
> In my web page there are a number of terms that need to be defined. I like
> the user to be able to hover over the term and get the definition that way.
> For example:
>
> <dfn title="Made famous in the &#8216;Star Trek&#8217 TV
> series>teleportation</dfn>
>
> ... produces
>
> Made famous in the 'Star Trek' TV series
>
> ... when the user hovers over the defined term 'teleportation'.
>
> I would prefer the words 'Star Trek' to appear in italics instead (yes, I am
> fussy). Is there any way to do this?

While superficially attractive, @title is a problematic tool to use
for inline progressive disclosure of definitions because:

    * It cannot store text structure (such as changes of voice or language).

    * User agents do a terrible job of providing universal access to
information in @title. Popular user agents do not allow users to
access @title content using the keyboard (or a switch access device)
alone. Some user agents truncate long @title content. Popular screen
readers do not read @title on arbitrary elements - normally only on
<abbr>, <acronym>, <img>, and interactive controls like <a>, and then
depending on configuration.

In general, I'd strongly recommend putting your definitions in plain
view, along with anything else users might want to read:

    <dfn>teleportation</dfn>, made famous in the <cite>Star
Trek</cite> TV series

Simple, robust, understood.

For lengthier definitions, ordinary hyperlinks to a glossary on the
same page or a definition on another page are a tried and tested,
universally familiar, universally accessible progressive disclosure
pattern:

    <a href="teleportation.html">teleportation</a>

    <a href="#glossary-teleportation">teleportation</a>

    <a href="glossary.html#teleportation">teleportation</a>

Any deviation from either plain view or simple hyperlinks is going to
introduce unnecessary barriers to consuming your content.

Still, we can think about ways to make your content harder to consume,
if you like. ;)

You could build on the hyperlinks approach by using JS to extract the
HTML in the #teleportation fragment and display it when the term is
hovered.

Alternatively, you could build on the plain view approach with
something more complicated such as:

    <span class="term-defined"
tabindex="0"><dfn>teleportation</dfn><span class="definition">, made
famous in the <cite>Star Trek</cite> TV series</span></span>

   /* Distinguish the defined term so that users have some sort of hint
      it might be a control. At least this gives users of caret navigation
      a chance. */
   .term-defined dfn {
          border: 1px solid red;
          padding: 3px;
    }

    /* Hide offscreen left to be read by screen readers. */
    .term-defined .definition {
          left: -99999px;
          position: absolute;
    }

    /* Show the definition on keyboard focus or hover. */
    .term-defined:focus .definition,
    .term-defined:hover .definition {
          position: static;
    }

Leaving aside the usability issues raised by your question and
focusing purely on the technicalities, you can extract and style
content in attributes using CSS generated content, e.g.:

    dfn:hover:before { content: attr(title); }

However, you can't apply transform punctuation within the raw text
content into italics with CSS alone, for that you'd need JS too.

Hope that helps.

--
Benjamin Hawkes-Lewis


*******************************************************************
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [email protected]
*******************************************************************

Reply via email to