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

2K+ 瀏覽

開啟你的 職業生涯

完成課程獲取認證

開始吧
廣告