------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css"> <!-- Link to your external CSS file -->
<title>Your Webpage Title</title>
</head>
<body>
<div class="grad"></div> <!-- Your HTML element with the "grad" class -->
</body>
</html>
@keyframes example {
0% { background-color: red; left: 0px; top: 0px; }
25% { background-color: yellow; left: 200px; top: 0px; }
50% { background-color: blue; left: 200px; top: 200px; }
75% { background-color: green; left: 0px; top: 200px; }
100% { background-color: red; left: 0px; top: 0px; }
}
.grad {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
}
-----------------------------------------------------------------------------------------------------------------------------
Animation Box Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css"> <!-- Link to your external CSS file -->
<title>Your Webpage Title</title>
</head>
<body>
<div class="animated-box"></div>
</body>
</html>
CSS
:root {
--animation-duration: 4s; /* Animation duration */
--box-height: 100px; /* Initial height of the box */
--box-color-1: #3498db; /* Initial color */
--box-color-2: #e74c3c; /* Color during animation */
}
@keyframes moveAndChangeColor {
0%, 100% {
width: var(--box-height);
background-color: var(--box-color-1);
top: 0;
}
50% {
width: calc(var(--box-height) * 2);
background-color: var(--box-color-2);
top: calc(100vh - var(--box-height));
}
}
.animated-box {
width: var(--box-height);
height: var(--box-height);
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
background-color: var(--box-color-1);
animation: moveAndChangeColor var(--animation-duration) ease-in-out infinite;
}
-----------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
@keyframes exampleAnimation {
0% {
transform: scale(1);
background-color: red;
}
50% {
transform: scale(1.2);
background-color: yellow;
}
100% {
transform: scale(1);
background-color: red;
}
}
.animated-element {
width: 100px;
height: 100px;
background-color: red;
animation: exampleAnimation 3s infinite; /* Animation name, duration, and iteration count */
}
</style>
<title>CSS Animation Example</title>
</head>
<body>
<div class="animated-element"></div>
</body>
</html>
Comments
Post a Comment