Simple tooltip - Title Attribute?

2019-02-17 11:48发布

问题:

When I want to have a message show when a user mouse overs an object, and lately I just use the title attribute on my html tags since it's simple and automatically doesn't go off screen.

Question: Is using the title attribute is a bad thing to rely on for a tool-tip?

Ignoring the fact you can't customize it, I'm curious about functionality over using a custom made tool-tip (such as how the standard user interacts with it). A specific web-comic I read, for example, uses the title attribute to add a witty comment / factoid when you hover over it. Yet not many people seem to know about it.

As such it seems a title might be good for a comment, or even saying author of a picture, but is it good for a true simply tool-tip?

Considering for a 'real' tool-tip you need usually 1-2 extra elements, css (and depending how you set it up, possibly some inline style for placement), and possibly even java-script, is the title attribute bad to use since (again) it cannot be customized, is often a small off-topic detail about the element, and only appears after a set amount of time.

Note: If it helps (food for thought), my current situation that brought this question on, is I like when a site has something like [?] for you to hover over to find more details without shoving them into the page, thus keeping it simple. Also, I learned html from w3schools, and they never mention the title attribute, so not really sure what they are intended / should be used for. (and yes, mentioning w3schools part was a (bad) attempt at getting sympathy)

And I find this question kind of weird to ask considering SO uses them quite a bit, but feel free to assume I know nothing about it as... well... I really don't)

回答1:

The title attribute (@title), should not be used.

  1. Every browser does their own thing with the @title, even though it looks the same.
  2. For people who just use the keyboard, they cannot get the information in @title.
  3. People accessing the site from a mobile device, cannot get the information.
  4. Some, but not all assistive technology can get the information in the @title
    1. some allows it to be read after enabling it. Which not many people (users) know about.
    2. other technology simply ignores the link text and reads the @title only.

Ex of 4.2:

<a href="#" title="Are you sure?">Delete your account</a>

This will read:

Are you sure? Link

Further Reading: PG: Title attribute



回答2:

First of all,hats off to your question. Good thinking. I guess we people [I'm speaking about amateur coders like me] needn't develop a big site or rather lack that expertise. We simple need to keep getting our things done in an optimized manner. Therefore, similarily, I have also encountered almost every script using title for tooltips. Guess,it's the simple way to tackle it. Moreover, as long as the tooltip is attractive, isn't slow, and caters our need: its all good.



回答3:

The title attribute is simple, and simplistic. It is not reliable. No tooltip mechanism really is, but the tooltips generated by title attributes have rather poor usability: tiny font size, problems with line control, timed disappearance, no way (to normal users) to make it stay put so that you can actually read it even if you are a slow reader. Besides, there is normally no hint to the user about the availability of a tooltip.



标签: html tooltip