TEST
unknown
plain_text
a year ago
1.4 kB
9
Indexable
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tooltip on Click</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="tooltip-container">
<button id="tooltipButton">Click me</button>
<div id="tooltip" class="tooltip">This is a tooltip message!</div>
</div>
<script src="script.js"></script>
</body>
</html>
.tooltip-container {
position: relative;
display: inline-block;
}
.tooltip {
visibility: hidden;
width: 140px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 5px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%; /* Position above the button */
left: 50%;
margin-left: -70px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip::after {
content: '';
position: absolute;
top: 100%; /* At the bottom of the tooltip */
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: black transparent transparent transparent;
}
.tooltip-container .show-tooltip {
visibility: visible;
opacity: 1;
}
document.getElementById('tooltipButton').addEventListener('click', function() {
var tooltip = document.getElementById('tooltip');
tooltip.classList.toggle('show-tooltip');
});
Editor is loading...
Leave a Comment