alt text not showing when hovering over image

巧了我就是萌 提交于 2020-01-13 09:11:20

问题


i have the following code:

<td><%= link_to(image_tag("delete.gif", :size => "16x16", :alt => "Delete Entry"), phone, :confirm => 'Are you sure?', :method => :delete, :remote=>true, :class=>'delete_phone') %></td>  

in my view. Now, it all works fine and does what I need it to, but when I hover over the icon, well, it doesn't show me any text. I've tried in Firefox and Chrome.

Has anyone else come across the same issue?

Thanks!


回答1:


#protip - it can be a painful (and very un-DRY) exercise to add titles for all your images. To make this a lot less painful all my apps ship with this JS (require jquery):

$(function() {
  $('img').each( function() {
    var o = $(this);
    if( ! o.attr('title') && o.attr('alt') ) o.attr('title', o.attr('alt') );
  });
});

This sets the title of any img without a title to the value of it's alt attribute.




回答2:


Use title, not alt, and your problems will be solved! Alt is for accessibility - it means "alternate". Title is what you'd use for a tooltip.




回答3:


I have no idea about Ruby, but you need to use the title attribute in HTML to get the rollover text appearing in most browsers.. Does that help at all?

eg

<img title="hello thar" src="hellothar.gif" />



回答4:


On hover image title text is shown in tooltip.

Alt text is for users with disabled images (or slow connection) and search engines




回答5:


Use title option to display text in rails 3.

<%= image_tag 'Profile.png',:title => 'Profile'  %>

When mouse hover over the Profile.png, it will show the text Profile.



来源:https://stackoverflow.com/questions/5814595/alt-text-not-showing-when-hovering-over-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!