Skip to content
PHP Logo

Are there alternative methods to display tooltip text for objects like rectangles or polygons in PHP?

When working with shapes like rectangles or polygons in PHP, there is no built-in tooltip functionality like in HTML. However, you can create a tooltip effect by using JavaScript and CSS. By adding event listeners to the shapes and displaying a tooltip element on hover, you can achieve a similar effect.

php
<?php
// PHP code to generate a rectangle with tooltip using JavaScript and CSS

echo '<div class="rectangle" onmouseover="showTooltip()" onmouseout="hideTooltip()"></div>';
echo '<div id="tooltip" style="display: none;">Tooltip text here</div>';
?>

<script>
function showTooltip() {
    document.getElementById('tooltip').style.display = 'block';
}

function hideTooltip() {
    document.getElementById('tooltip').style.display = 'none';
}
</script>

<style>
.rectangle {
    width: 100px;
    height: 50px;
    background-color: blue;
}

#tooltip {
    position: absolute;
    background-color: black;
    color: white;
    padding: 5px;
}
</style>