ฟังก์ชันCSS radial-gradient()
ตัวอย่าง
การไล่ระดับสีแบบรัศมีพร้อมการหยุดสีที่เว้นระยะเท่ากัน:
#grad {
background-image: radial-gradient(red, green, blue);
}
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
ฟังก์ชัน Radial-gradient() ตั้งค่าการไล่ระดับสีในแนวรัศมีเป็นภาพพื้นหลัง
การไล่ระดับสีในแนวรัศมีถูกกำหนดโดยจุดศูนย์กลาง
ในการสร้างการไล่ระดับสีในแนวรัศมี คุณต้องกำหนดจุดหยุดสีอย่างน้อยสองจุด
ตัวอย่างของ Radial Gradient:
รุ่น: | CSS3 |
---|
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่รองรับฟังก์ชันนี้อย่างเต็มที่
ตัวเลขตามด้วย -webkit-, -moz- หรือ -o- ระบุเวอร์ชันแรกที่ทำงานกับคำนำหน้า
Function | |||||
---|---|---|---|---|---|
radial-gradient() | 26.0 10.0 -webkit- |
10.0 | 16.0 3.6 -moz- |
6.1 5.1 -webkit- |
12.1 11.6 -o- |
ไวยากรณ์ CSS
background-image: radial-gradient(shape size at position, start-color, ..., last-color);
Value | Description |
---|---|
shape | Defines the shape of the gradient. Possible values:
|
size | Defines the size of the gradient. Possible values:
|
position | Defines the position of the gradient. Default is "center" |
start-color, ..., last-color | Color stops are the colors you want to render smooth transitions among. This value consists of a color value, followed by an optional stop position (a percentage between 0% and 100% or a length along the gradient axis). |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
การไล่ระดับสีแบบรัศมีพร้อมสต็อปสีที่เว้นระยะต่างกัน:
#grad {
background-image: radial-gradient(red 5%, green 15%, blue 60%);
}
ตัวอย่าง
การไล่ระดับสีในแนวรัศมีที่มีรูปร่างเป็นวงกลม:
#grad {
background-image: radial-gradient(circle, red, yellow, green);
}
ตัวอย่าง
การไล่ระดับสีแบบรัศมีพร้อมคำหลักที่มีขนาดต่างกัน:
#grad1 {
background-image: radial-gradient(closest-side at 60% 55%, blue, green, yellow, black);
}
#grad2 {
background-image: radial-gradient(farthest-side at 60% 55%, blue, green, yellow, black);
}
หน้าที่เกี่ยวข้อง
กวดวิชา CSS: CSS การไล่ระดับสี