使用 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>

更新日期:24-Jun-2020

328 次檢視

開啟你的 職業生涯

完成課程即可獲得認證

開始
廣告