1

Can I add this to a image? I tried but its not working.

img[title]:hover:after {
  content: attr(title);
  padding: 3px 3px 3px 3px;
  margin-top: 4px;
  background: #000;
  position: absolute;
  z-index: 9999;
}
<img title="Online" alt="Online" height="16px" style="margin-top:-5px;" src="https://cdn0.iconfinder.com/data/icons/weboo-2/512/tick.png">
m4n0
  • 29,823
  • 27
  • 76
  • 89
  • possible duplicate of http://stackoverflow.com/questions/2011142/how-to-change-the-style-of-title-attribute-inside-the-anchor-tag – code.rider Dec 11 '15 at 11:30
  • Related - http://stackoverflow.com/questions/11672946/styling-an-image-title-attribute-using-css – Paulie_D Dec 11 '15 at 11:31

1 Answers1

1

Since pseudo elements do not work with img, I suggest you to wrap it inside a div and then use the properties. Use can use the data-* attributes to replace the title attribute of image.

.image-container:hover:after {
  content: attr(data-title);
  padding: 3px 3px 3px 3px;
  margin-top: 4px;
  background: #000;
  position: absolute;
  z-index: 9999;
  color: #fff;
}
<div class="image-container" data-title="Online">
  <img alt="Online" height="16px" style="margin-top:-5px;" src="https://cdn0.iconfinder.com/data/icons/weboo-2/512/tick.png">
</div>
Community
  • 1
  • 1
m4n0
  • 29,823
  • 27
  • 76
  • 89