Explore Transition Properties and Syntax
In this step, you'll dive deeper into CSS transition properties and learn about the full syntax for creating more complex and precise transitions.
Update the styles.css
file to explore different transition properties:
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
gap: 20px;
}
.box {
width: 100px;
height: 100px;
background-color: #3498db;
display: flex;
justify-content: center;
align-items: center;
color: white;
cursor: pointer;
/* Full transition syntax */
transition-property: background-color, transform, border-radius;
transition-duration: 0.5s, 0.3s, 0.4s;
transition-timing-function: ease-in-out, linear, ease;
transition-delay: 0s, 0.1s, 0s;
}
.box:hover {
background-color: #2980b9;
transform: scale(1.2) rotate(15deg);
border-radius: 50%;
}
Let's break down the transition properties:
-
transition-property
: Specifies which CSS properties to transition
- Can be multiple properties separated by commas
all
can be used to transition all changeable properties
-
transition-duration
: Sets the time the transition will take
- Can have different durations for different properties
- Specified in seconds (s) or milliseconds (ms)
-
transition-timing-function
: Controls the speed curve of the transition
linear
: Constant speed
ease-in
: Starts slow, accelerates
ease-out
: Starts fast, decelerates
ease-in-out
: Slow start and end
-
transition-delay
: Adds a delay before the transition starts
- Useful for creating sequential or staggered effects
Alternatively, you can use the shorthand transition
property:
.box {
transition:
background-color 0.5s ease-in-out,
transform 0.3s linear 0.1s,
border-radius 0.4s ease;
}
Update the index.html
to include multiple boxes for demonstration:
<body>
<div class="container">
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
</div>
</body>
When you hover over the boxes, you'll see:
- Different transition properties
- Varied timing and delays
- Multiple transformations happening simultaneously