probier mal so:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Tooltip Beispiel</title>
</head>
<body>
<a href="ziel-seite.html" class="tooltip-container">
Linktext
<span class="tooltip">
<img src="vorschaubild.jpg" alt="Vorschaubild">
</span>
</a>
<script src="script.js"></script>
</body>
</html>
CSS
.tooltip-container {
position: relative;
text-decoration: none;
}
.tooltip {
display: none;
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
background-color: #fff;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.tooltip img {
max-width: 100px; /* Passen Sie die Größe des Vorschaubilds nach Bedarf an */
}
.tooltip-container.hovered .tooltip {
display: block;
}
JS
// Überprüfen, ob das Gerät einen Touchscreen hat
function isTouchDevice() {
return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
}
const tooltipContainer = document.querySelector('.tooltip-container');
// Nur auf Geräten ohne Touchscreen den Hover-Effekt hinzufügen
if (!isTouchDevice()) {
tooltipContainer.addEventListener('mouseenter', () => {
tooltipContainer.classList.add('hovered');
});
tooltipContainer.addEventListener('mouseleave', () => {
tooltipContainer.classList.remove('hovered');
});
}