There are plenty of JavaScript-based libraries that show tooltips when you hover your mouse over a certain area of a web page. Some are rather plain, some allow the tooltip to display HTML content styled with CSS.
But is there a way to show a styled tooltip without using JavaScript? If you just use the title
attribute, tags are not processed (e.g. foo<br />bar
doesn't produce a line break). I'm looking for a solution that allows one to display styled HTML content without using any JavaScript.
HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .
You can create custom CSS tooltips using a data attribute, pseudo elements and content: attr() eg. Show activity on this post.
HTML title Attribute The title attribute specifies extra information about an element. The information is most often shown as a tooltip text when the mouse moves over the element. The title attribute can be used on any HTML element (it will validate on any HTML element.
Via data attributes − To add a tooltip, add data-toggle = "tooltip" to an anchor tag. The title of the anchor will be the text of a tooltip. By default, tooltip is set to top by the plugin.
I have made a little example using css
.hover { position: relative; top: 50px; left: 50px; } .tooltip { /* hide and position tooltip */ top: -10px; background-color: black; color: white; border-radius: 5px; opacity: 0; position: absolute; -webkit-transition: opacity 0.5s; -moz-transition: opacity 0.5s; -ms-transition: opacity 0.5s; -o-transition: opacity 0.5s; transition: opacity 0.5s; } .hover:hover .tooltip { /* display tooltip on hover */ opacity: 1; }
<div class="hover">hover <div class="tooltip">asdadasd </div> </div>
FIDDLE
http://jsfiddle.net/8gC3D/471/
Using the title attribute:
<a href="#" title="Tooltip here">Link</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With