Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Perform Animation on CSS border-top-right-radius property
The CSS border-top-right-radius property defines the radius of the top-right corner of an element's border. You can create smooth animations on this property to create engaging visual effects.
Syntax
selector {
border-top-right-radius: value;
animation: animation-name duration timing-function;
}
@keyframes animation-name {
from { border-top-right-radius: initial-value; }
to { border-top-right-radius: final-value; }
}
Example: Animating Border Top Right Radius
The following example demonstrates how to animate the border-top-right-radius property from 0 to 80px −
<!DOCTYPE html>
<html>
<head>
<style>
.animated-box {
width: 300px;
height: 150px;
background-color: #4CAF50;
border: 5px solid #2E7D32;
margin: 50px auto;
animation: corner-animation 2s ease-in-out infinite alternate;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
}
@keyframes corner-animation {
0% {
border-top-right-radius: 0px;
background-color: #4CAF50;
}
100% {
border-top-right-radius: 80px;
background-color: #FF5722;
}
}
</style>
</head>
<body>
<h2>Border Top Right Radius Animation</h2>
<div class="animated-box">
Watch the top-right corner!
</div>
</body>
</html>
A green box animates continuously, with its top-right corner changing from sharp (0px radius) to rounded (80px radius) while the background color transitions from green to red. The animation alternates back and forth every 2 seconds.
Example: Multi-Stage Animation
This example shows a more complex animation with multiple keyframe stages −
<!DOCTYPE html>
<html>
<head>
<style>
.multi-stage-box {
width: 200px;
height: 200px;
background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
border: 3px solid #333;
margin: 50px auto;
animation: multi-corner 4s ease-in-out infinite;
}
@keyframes multi-corner {
0% {
border-top-right-radius: 0px;
}
25% {
border-top-right-radius: 50px;
}
50% {
border-top-right-radius: 100px;
}
75% {
border-top-right-radius: 25px;
}
100% {
border-top-right-radius: 0px;
}
}
</style>
</head>
<body>
<h2>Multi-Stage Corner Animation</h2>
<div class="multi-stage-box"></div>
</body>
</html>
A square box with gradient background performs a 4-second animation where the top-right corner radius changes through multiple stages: starts at 0px, grows to 50px, then 100px, reduces to 25px, and finally returns to 0px, creating a smooth morphing effect.
Conclusion
Animating the border-top-right-radius property creates smooth corner transformations that enhance user interface design. Use keyframes to control the animation timing and combine with other properties for more dynamic effects.
Advertisements
