How to display simple tooltips on icons in html?

I use ActiveScaffold in a Ruby on Rails application, and to save space in the table, I replaced the default text โ€œactionsโ€ in the table (for example, โ€œeditโ€, โ€œdeleteโ€, โ€œshowโ€) with icons using CSS. I also added some custom actions with action_link.add ("move" and "copy").

For clarity, I want a tooltip with a related action (ie, โ€œeditโ€, โ€œcopyโ€) when I hover over the icon.

I thought I could do this by adding a simple definition of "alt" to the tag, but this does not work.

Can someone point me in the right direction?

+4
source share
9 answers

The alt attribute should be used as an alternative to the image if there is no image or only text in the browser.

IE made a mistake when they made alt as a tooltip. It was never meant to be.

The correct attribute for this is title , which of course does not make a tooltip in IE.

So, so that the tooltip is displayed in both IE and FireFox / Safari / Chrome / Opera, use the alt attribute and the title attribute.

+16
source

Just a small point to add to this thread ... there is no alt tag or header tag. The alt attribute is for images, but all other elements on the page may have a title attribute, which is the best choice for browser compatibility.

 <span title="Click here to edit the foo"> Edit </span> 
+9
source

You need the "title" tag. I'm not sure if this is needed anymore, but I usually add alt and title tags to make sure all browsers display a tooltip of the same.

+2
source

HTML hints are the contents of the alt text for image tags, but if you set this using CSS, you probably have a background:url(...); style background:url(...); instead of an image.

+1
source

Use alt for images and title for links.

+1
source

The alt property of the img tag works in some browsers, but not in all (for example, on some mozilla-based models).

the " right way " to use this title property.

+1
source

As Prestole noted, the alt tag should work for images and link headers. However, it depends on the browser ... most browsers should implement functionality that displays this metadata in the form of hints, but they are not required to do this.

0
source

Understanding, as Joel Coehoom noted, my icon was actually a background image, I created a transparent image with a caption and alt attributes on top of the background, and voila - tooltips!

0
source
0
source

Source: https://habr.com/ru/post/1276667/


All Articles