使用 CSS 将背景图像设置为固定


使用 background-attachment 属性将背景图像显示为固定。

示例

你可以尝试运行下面的代码来实现 background-attachment 属性 −

在线示例

<!DOCTYPE html>
<html>
   <head>
      <style>
         body {
            background-image: url("https://tutorialspoint.com/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 次浏览

开启你的 职业生涯

完成课程即可获得认证

开始
广告
© . All rights reserved.