Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a rich tooltip with a HTML form in it

I have a paragraph of text with a link in it. I want to make a rich tool tip with a title on the top and a field to collect email addresses appear on hovering the link. What approach should I take?

I have looked into tool tip libraries but none seem to have form support. Please find the code below

The content in which the link is present:

<p>Pellentesque habitant <a href="#">Link to show tooltip</a> morbi senectus  
tristique senectus et netus et malesuada pellentesque habitant senectus 
fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies  
eget,  tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.  
Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>

Tool tip content:

<div class="tooltip">
  <h3>Tooltip title</h3>
  <p>Vestibulum tortor quam, feugiat vitae, ultricies  
  eget,  tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.  
  Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
  <form>
    <input type="email" placeholder="[email protected]" />
    <input type="submit" value="subscribe" />
  </form>
  <span class="branding">This is our branding message</span>
</div>

Now the effect I want to achieve is when I hover the link in the content the tooltip content should appear in a styled div. How should I do it?

like image 358
Sathish Manohar Avatar asked Sep 07 '16 06:09

Sathish Manohar


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

How do I add a tooltip to a form?

To add a tooltip to a form field, do the following: Double-click a selected form field to open the Properties window. In the General tab, type a description into the tooltip box.

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.


1 Answers

Check this snippet

Updated

$("a").bind("mousemove", function(event) {
    $("div.tooltip").css({
        top: event.pageY + 10 + "px",
        left: event.pageX + 10 + "px"
    }).show();
})
$('.close').bind('click', function(){
  $("div.tooltip").fadeOut();
});
body{
    font-family:arial;
    font-size:12px;
}
.tooltip {
    width:350px;
    position:absolute;
    display:none;
    z-index:1000;
    background-color:#CB5757;
    color:white;
    border: 1px solid #AB4141;
    padding:15px 20px;
    box-shadow: 0px 3px 2px #8D8D8D;
    border-radius: 6px;
}
.close{
  right: 15px;
  position: absolute;
  background: #fff;
  color: #555;
  width: 20px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  border-radius: 50%;
  font-size: 10px;
  cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main">
<p>Pellentesque habitant <a href="#">Link to show tooltip</a> morbi senectus  
    tristique senectus et netus et malesuada pellentesque habitant senectus 
    fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies  
    eget,  tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.  
    Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
</p>
<div class="tooltip">
    <span class="close">X</span>
    <h3>Tooltip title</h3>
    <p>Vestibulum tortor quam, feugiat vitae, ultricies  
        eget,  tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.  
        Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
    </p>
    <form>
        <input type="email" placeholder="[email protected]" />
        <input type="submit" value="subscribe" />
    </form>
    <span class="branding">This is our branding message</span>
</div>
like image 89
Hitesh Misro Avatar answered Oct 26 '22 15:10

Hitesh Misro