เพื่อกำหนดชื่อคุณสมบัติ CSS ที่ transition effect จะใช้งาน ให้ใช้ transition-property
ในตัวอย่างด้านล่าง เรากำหนด property เป็น width และ duration ด้วย:
ตัวอย่างโค้ด
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 150px;
height: 150px;
background: blue;
transition-property: width;
transition-duration: 3s;
}
div:hover {
width: 250px;
}
</style>
</head>
<body>
<h1>Heading One</h1>
<p>Hover เมาส์ที่กล่องด้านล่างเพื่อเปลี่ยนความกว้าง:</p>
<div></div>
</body>
</html>
คำอธิบาย: แทนที่จะใช้ shorthand transition: width 3s สามารถแยกเป็น transition-property: width และ transition-duration: 3s ได้ เหมาะสำหรับกรณีที่ต้องการ transition หลาย property แต่ duration คนละค่า