Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Set top tooltip with CSS
To set a top tooltip with CSS, you position the tooltip above the element using the bottom property along with position: absolute. The tooltip appears above the trigger element when hovered.
Syntax
.tooltip .tooltip-text {
position: absolute;
bottom: 100%;
visibility: hidden;
}
.tooltip:hover .tooltip-text {
visibility: visible;
}
Example
The following example creates a tooltip that appears at the top when you hover over the text −
<!DOCTYPE html>
<html>
<head>
<style>
.mytooltip {
position: relative;
display: inline-block;
margin-top: 60px;
background-color: #f0f0f0;
padding: 10px 15px;
border: 1px solid #ccc;
cursor: pointer;
}
.mytooltip .mytext {
visibility: hidden;
width: 140px;
background-color: #333;
color: white;
text-align: center;
border-radius: 6px;
padding: 8px;
position: absolute;
z-index: 1;
bottom: 100%;
left: 50%;
margin-left: -70px;
margin-bottom: 5px;
}
.mytooltip:hover .mytext {
visibility: visible;
}
/* Optional: Add arrow pointing down */
.mytooltip .mytext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #333 transparent transparent transparent;
}
</style>
</head>
<body>
<div class="mytooltip">Hover over me
<span class="mytext">This tooltip appears on top!</span>
</div>
</body>
</html>
A gray box with text "Hover over me" appears. When you hover over it, a dark tooltip with white text "This tooltip appears on top!" shows above the box with a small arrow pointing down.
Key Properties
| Property | Purpose |
|---|---|
bottom: 100% |
Positions tooltip above the element |
position: absolute |
Allows precise positioning |
visibility: hidden/visible |
Controls tooltip display on hover |
z-index: 1 |
Ensures tooltip appears above other elements |
Conclusion
Top tooltips are created using bottom: 100% to position the tooltip above the trigger element. The visibility property controls when the tooltip appears on hover, creating an interactive user experience.
Advertisements
