CSS में टूलटिप को सही ढंग से पोजीशन करने के लिए top, right, bottom, और left प्रॉपर्टीज का उपयोग किया जाता है। टूलटिप कंटेनर पर position: relative और टूलटिप टेक्स्ट पर position: absolute होना आवश्यक है।
उदाहरण: राइट पोजीशन टूलटिप
नीचे दिए गए उदाहरण में टूलटिप को ट्रिगर एलिमेंट के दाईं ओर पोजीशन किया गया है।
<!DOCTYPE html>
<html>
<style>
.mytooltip .mytext {
visibility: hidden;
width: 140px;
background-color: blue;
color: #fff;
z-index: 1;
top: -6px;
left: 100%;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
}
.mytooltip {
position: relative;
display: inline-block;
}
.mytooltip:hover .mytext {
visibility: visible;
}
</style>
<body>
<div class="mytooltip">Keep mouse cursor over me
<span class="mytext"> My Tooltip text</span>
</div>
</body>
</html>
पोजीशनिंग के लिए मुख्य प्रॉपर्टीज:
top/bottom: वर्टिकल पोजीशनleft/right: हॉरिजॉन्टल पोजीशनtransform: सेंटरिंग के लिए (जैसेtranslateX(-50%))