
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
How to Create Link Tooltip Using CSS3 and jQuery?
In this article, we will look to approach to Creating Link Tooltip Using CSS3 and jQuery.
When an element or link hovers over, link tooltips are an excellent method to show more information. There are various methods for doing this. When a link hovers over, tooltips are utilized to offer additional information.
Multiple Approaches
We have provided the solution in different approaches.
- By Using mouseenter and mouseleave functions of jquery.
- By Using tooltip() function.
- Using only CSS to create tooptips
Approach-1:By Using mouseenter and mouseleave functions of jquery
jQuery uses the mouseenter and mouseleave functions to carry out this action. −
The mouseenter event is fired at an Element when a pointing device (usually a mouse) is initially moved so that its hotspot is within the element at which the event was fired.The mouseleave event is fired at an Element when the cursor of a pointing device (usually a mouse) is moved out of it.
Syntax
In HTML, we use the following syntax of the mouseenter and mouseleave in the jquery −
addEventListener('mouseleave', (event) => {}); addEventListener('mouseenter', (event) => {});
Example
In the following section, we will design the code using mouserenter and the mouseleave function of jquery. A link named “Hover Over me! “ is created using the <a> tag and here when the user will hoover over this link a given text will appear to the user.
<!DOCTYPE html> <html> <head> <style> .tooltip { display: none; position: absolute !important; width: 200px; padding: 10px; margin: 0 0 3px 0; color: #fff; z-index: 1; font-size: 50px; text-decoration: none; text-align: center; } .tooltip:after { position: absolute !important; bottom: -14px; z-index: 1; } .tooltip:before { content: ""; position: absolute !important; bottom: -14px; z-index: 100; } </style> </head> <body> <a href="#" class="link" title="Welcome to tutorials points" class="tooltip_link left"> Hover over me! </a> <script> $("a").mouseenter(function (e) { var $x = e.pageX - this.offsetLeft; var $tooltip_text = $(this).attr("title"); $(this).append('<div class="tooltip">'+ $tooltip_text + '</div>'); $("a > div.tooltip.").fadeIn(300); }); $("a").mouseleave(function () { $("a > div.tooltip.").fadeOut(300).delay(300)(function () { $(this).remove(); }); }); </script> </body> </html>
After hovering mouse on “Hover over me!”, the output is
Welcome to tutorials points
Approach-2:By Using tooltip() function
Using jQuery UI − The tooltip widget of jQuery UI helps to customize tooltips. The tooltip() method is used to add tooltip to any element.
Tooltips can be attached to any element. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element, just like a native tooltip.
jQueryUI provides tooltip() method to add tooltip to any element on which you want to display tooltip. This gives a fade animation by default to show and hide the tooltip, compared to just toggling the visibility.
Syntax
$(selector, context).tooltip (options) Method $(selector, context).tooltip ("action", [params]) Method
Example
In the below code, we have used the tooltip() wedge to customize the created tooltip in the above example, here we have used the attribute type of the style tag of HTML and under it, we have added the properties as we want the tooltip should appear or is required by the user.
<!DOCTYPE html> <html lang="en"> <head> <link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"rel="stylesheet"> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <style type="text/css"> .hi { text-decoration: none; color: blue; } </style> </head> <body> <a class="hi" id="myTooltip"href="#" title="Welcome to tutorials points"> Hover Over me! </a> <script> $(function () { $("#myTooltip").tooltip(); }); </script> </body> </html>
Approach-3: Using only CSS to create tooptips:
In this approach, we have only used the CSS to create tooltip as per the requirement. Manly using the hover property of the CSS which is responsible when the user hovers the mouse and it becomes the tooltips.
The − hover selector is used to selecting elements when you mouse over them.
Example
In this program, we are only using the CSS properties to create a tooltip as per the requirement. Here, when the user will hover over the link it will become tooltips and a given message will appear to the user.
<!DOCTYPE html> <html> <head> <style> body { text-align: center; } .t_t { position: relative; display: inline-block; margin-top: 3rem; } .t_t .tooltiptext { width: 8rem; text-align: center; border-radius: 4px; background-color: blue; color: #fff; padding-top: 9px; padding-bottom: 9px; position: absolute; z-index: 1; bottom: 165%; margin-left: -55px; left: 50%; transition: opacity 0.5s; visibility: hidden; } .t_t .tooltiptext::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: green transparent transparent; } .t_t:hover .tooltiptext { visibility: visible; } </style> </head> <body> <div class="t_t">Hover over me! <span class="tooltiptext"> Welcome to tutorials Point </span> </div> </body> </html>
Supported Browsers − The browsers supported by pointer-events Property are listed below −
- Google Chrome 1.0
- Edge 12.0
- Internet Explorer 11.0
- Firefox 1.5
- Opera 9.0
- Safari 4.0
This article focused on How to Create Link Tooltip Using CSS3 and jQuery by using three different approaches.
- Related Articles
- How to handle a link click event using jQuery?
- How to add target=”_blank” to a link using jQuery?
- How to link jQuery from Google CDN?
- How to link jQuery in HTML page?
- How to create div dynamically using jQuery?
- How to create a link from a text using JavaScript?
- How to Create CSS3 Keyframe Animations?
- How to create CSS3 Rounded Corners?
- How to create CSS3 Transition Effects?
- How to create CSS3 Box and Text Shadow Effects?
- How to link jQuery from my local machine?
- How to create HTML link that doesnt follow the link?
- How to create and share an Auto-subscribe link?
- How to Verify Tooltip using Selenium WebDriver?
- How to capture tooltip in Selenium using getAttribute?
