<div>
<span data-customTooltip="Tooltip text" class="hoverElement">
Hover on me to see tooltip
</span>
</div>
<!-- Other Implementations deom -->
<div class="icons-container">
<p class="text">Other implementations demo...</p>
<div class="icons-wrapper">
<i data-customTooltip="Home" class="fas fa-home"></i>
<i data-customTooltip="Feed" class="fas fa-rss-square"></i>
<i data-customTooltip="Messages" class="fas fa-envelope"></i>
<i data-customTooltip="Notifications" class="fas fa-bell"></i>
</div>
</div>
/* ------- General Styles (has nothing to do with tooltip style) ------- */
@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;1,400&display=swap");
body {
font-family: "Roboto", sans-serif;
background-color: #d6d6d6;
}
.hoverElement {
background-color: lightblue;
padding: 6px 10px;
border-radius: 5px;
margin: 30%;
top: 150px;
}
/* ------------ ------------------ -------------- */
/*------ Tooltip related styles start here -------- */
[data-customTooltip] {
cursor: pointer;
position: relative;
}
[data-customTooltip]::after {
background-color: #fff;
font-family: "Roboto", sans-serif;
font-weight: normal;
color: #222;
font-size: 14px;
padding: 8px 12px;
height: fit-content;
width: fit-content;
border-radius: 6px;
position: absolute;
text-align: center;
bottom: 0px;
left: 50%;
content: attr(data-customTooltip);
transform: translate(-50%, 110%) scale(0);
transform-origin: top;
transition: 0.14s;
box-shadow: 0 4px 14px 0 rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
}
[data-customTooltip]:hover:after {
display: block;
transform: translate(-50%, 110%) scale(1);
}
/* ----- Other implementations demo----- */
.icons-container {
margin-top: 300px;
}
.icons-wrapper {
display: flex;
align-items: center;
justify-content: space-around;
max-width: 500px;
margin: 0 auto;
background-color: #222;
border-radius: 6px;
}
.icons-wrapper > i.fas {
font-size: 30px;
color: #f6f6f6;
padding: 15px;
}
This Pen doesn't use any external JavaScript resources.