.icon {
background: #888;
padding: 15px;
border-radius: 8px;
width: 44px;
height: 44px;
line-height: 44px;
text-align: center;
position: relative;
font-size: 32px;
}
.tooltip {
position: absolute;
font-size: 16px;
width: 1px;
height: 1px;
padding: 0;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
background: black;
color: white;
line-height: normal;
top: 50%;
transform: translateY(-50%);
left: 90%;
padding: 3px 8px;
border-radius: 4px;
display: inline-block;
opacity: 0;
visibility: hidden;
transition: 0.2s;
&::before {
content: "";
right: 100%;
top: 50%;
transform: translateY(-50%);
position: absolute;
z-index: 1;
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid transparent;
border-right: 5px solid black;
}
.visible & {
width: auto;
height: auto;
clip: initial;
opacity: 1;
visibility: visible;
}
}
body {
height: 100vh;
margin: 0;
display: grid;
place-items: center;
}
View Compiled
import React, { useState } from "https://cdn.skypack.dev/react@17.0.1";
import ReactDOM from "https://cdn.skypack.dev/react-dom@17.0.1";
import Classnames from "https://cdn.skypack.dev/classnames@2.2.6";
const App = () => {
const [tooltipVisible, setTooltipVisible] = useState(false);
let timer = 0;
const TIMEOUT = 3000;
const classes = Classnames({
icon: true,
visible: tooltipVisible
});
function mouseEnter() {
timer = setTimeout(() => {
setTooltipVisible(true);
}, TIMEOUT);
}
function mouseLeave() {
setTooltipVisible(false);
clearTimeout(timer);
}
return (
<div
onMouseEnter={mouseEnter}
onMouseLeave={mouseLeave}
className={classes}
>
🤙
<span className="tooltip">Hang Loose</span>
</div>
);
};
ReactDOM.render(<App />, document.body);
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.