Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tooltip with HTML content without JavaScript

Tags:

html

css

tooltip

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.

like image 232
gaetanm Avatar asked Jun 30 '13 14:06

gaetanm


People also ask

How do I display HTML content in tooltip?

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" .

Can we add tooltip in CSS?

You can create custom CSS tooltips using a data attribute, pseudo elements and content: attr() eg. Show activity on this post.

Which attribute is used to add tooltip in HTML?

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.

How do I add a tag in tooltip?

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.


2 Answers

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/

like image 124
koningdavid Avatar answered Oct 06 '22 01:10

koningdavid


Using the title attribute:

<a href="#" title="Tooltip here">Link</a>
like image 23
heytools Avatar answered Oct 06 '22 01:10

heytools