使用 CSS 設定按鈕在影像上


你可以嘗試執行以下程式碼將按鈕設定在影像上

示例

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         .box {
            position: relative;
            width: 100%;
            max-width: 250px;
         }
         .box img {
            width: 100%;
            height: auto;
         }
         .box .btn {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
         }
      </style>
   </head>
   <body>
      <div class = "box">
         <img src = "https://tutorialspoint.tw/videotutorials/images/current_affairs_home.jpg" alt = "Current Affairs">
         <button class = "btn">Button</button>
      </div>
   </body>
</html>

更新時間: 2020-6-24

2K+ 瀏覽

啟動你的事業

完成課程即獲得認證

開始
廣告