การไล่ระดับสีเชิงเส้นใช้เพื่อจัดเรียงสีตั้งแต่สองสีขึ้นไปในรูปแบบเชิงเส้น เช่น บนลงล่าง หากต้องการเพิ่มความโปร่งใส ให้ใช้ฟังก์ชัน RGBA() และกำหนดจุดหยุดสี
ต่อไปนี้เป็นรหัสสำหรับตั้งค่าการไล่ระดับสีเชิงเส้นแบบโปร่งใสโดยใช้ CSS3 -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.linearGradient {
height: 200px;
background-image: linear-gradient(
to left,
rgb(111, 0, 255),
rgba(111, 0, 255, 0.616),
rgba(111, 0, 255, 0.384),
rgba(111, 0, 255, 0)
);
}
</style>
</head>
<body>
<h1>Linear Gradient with transparency</h1>
<div class="linearGradient"></div>
<h2>The above linear gradient goes from white to dark blue purple</h2>
</body>
</html> ผลลัพธ์
รหัสข้างต้นจะสร้างผลลัพธ์ต่อไปนี้ -
