Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

เปลี่ยน Opacity รูปภาพเมื่อวางเมาส์ (Mouse Over)


ใช้คุณสมบัติ opacity ร่วมกับ :hover selector เพื่อเปลี่ยนความทึบแสงเมื่อวางเมาส์ นี่คือโค้ดสำหรับเปลี่ยน Image Opacity เมื่อ Mouse Over −

ตัวอย่าง

<!DOCTYPE html> <html> <head> <style> body{    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } .transparent{    width:270px;    height:200px;    opacity: 1;    transition: 0.3s; } .transparent:hover{    opacity: 0.3; } </style> </head> <body> <h1>Image opacity on hover example</h1> <img class="transparent" src="https://i.picsum.photos/id/505/800/800.jpg" > <h2>Hover over the above image to change its opacity</h2> </body> </html>

ผลลัพธ์

โค้ดด้านบนจะแสดงผลดังนี้ −

เปลี่ยน Opacity รูปภาพเมื่อวางเมาส์ (Mouse Over)