Computer >> Máy Tính >  >> Lập trình >> CSS

Làm cách nào để tạo màu nền gradient trên cuộn bằng CSS?


Để tạo màu nền gradient trên cuộn, mã như sau -

Ví dụ

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      height: 250vh;
      color: white;
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      background: linear-gradient(
         141deg,
         #a47dff 0%,
         #4e28a7 40%,
         #22053d 65%,
         #72a4ff 75%
      );
   }
</style>
</head>
<body>
<h1>Change Background Gradient on Scroll Example</h1>
<p style="font-size: 30px;">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus, laborum minus? Vero accusantium laborum quas cum, sed obcaecati quibusdam dignissimos.
</p>
<h2 style="position:fixed;">Scroll to see the effect.</h2>
</body>
</html>

Đầu ra

Đoạn mã trên sẽ tạo ra kết quả sau -

Làm cách nào để tạo màu nền gradient trên cuộn bằng CSS?

Trong khi cuộn, gradient sẽ chuyển từ xanh lam đậm sang xanh lam nhạt -

Làm cách nào để tạo màu nền gradient trên cuộn bằng CSS?