使用 CSS 將背景影像設定為固定


使用 background-attachment 屬性可將背景圖片顯示為固定。

示例

你可以嘗試執行以下程式碼來實現 background-attachment 屬性 −

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         body {
            background-image: url("https://tutorialspoint.tw/videotutorials/images/tutor_connect_home.jpg");
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position: right top;
         }
      </style>
   </head>
   <body>
      <h1>Background Image</h1>
   </body>
</html>

更新於: 01-Jul-2020

681 檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告