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