Last active
April 13, 2021 00:15
-
-
Save w3collective/5b665643f670fe8095c507f07a19226d to your computer and use it in GitHub Desktop.
HTML tooltip on hover using CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>CSS Tooltip</title> | |
<style> | |
body { | |
padding: 10%; | |
} | |
[data-tooltip] { | |
position: relative; | |
cursor: pointer; | |
background: black; | |
color: white; | |
font-size: 12px; | |
border-radius: 1em; | |
padding: 0 0.5em; | |
} | |
[data-tooltip]:before { | |
content: attr(data-tooltip); | |
position: absolute; | |
opacity: 0; | |
width: 150px; | |
transform:translateX(-50%); | |
bottom: 25px; | |
padding: 0.5em; | |
background-color: black; | |
border-radius: 0.25em; | |
color: white; | |
text-align: center; | |
transition:0.2s; | |
} | |
[data-tooltip]:after { | |
content: ""; | |
position: absolute; | |
opacity: 0; | |
bottom: 15px; | |
margin-left: -5px; | |
border: 5px solid black; | |
border-color: black transparent transparent transparent; | |
transition:0.2s; | |
} | |
[data-tooltip]:hover:before, | |
[data-tooltip]:hover:after { | |
opacity: 1; | |
} | |
</style> | |
</head> | |
<body> | |
<p>Example CSS Tooltip <span data-tooltip="Tooltips are used to provide information about an element on a web page.">i</span></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source => https://w3collective.com/html-css-tooltip/