使用 CSS 建立使用者將滑鼠懸停在元素上時顯示的工具提示
你可以嘗試執行以下程式碼,以便在滑鼠懸停時建立可見的工具提示。使用可見性屬性
例項
<!DOCTYPE html> <html> <style> #mytooltip #mytext { visibility: hidden; width: 100px; background-color: black; color: #fff; text-align: center; border-radius: 3px; padding: 10px 0; position: absolute; z-index: 1; } #mytooltip:hover #mytext { visibility: visible; } </style> <body> <div id = "mytooltip">Hover the mouse over me <p id = "mytext">My Tooltip text</p> </div> </body> </html>
廣告