Анимация средствами CSS
Анимация подчеркивания при наведении
Код
<p class="hover-underline-animation">Hover this text to see the effect!</p>
HTML
.hover-underline-animation {
display: inline-block;
position: relative;
color: #0087ca;
}
.hover-underline-animation:after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 0;
left: 0;
background-color: #0087ca;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.hover-underline-animation:hover:after {
transform: scaleX(1);
transform-origin: bottom left;
}
CSS
Результат
Анимация сжатия кнопки
Код
<button class="button-shrink">Submit</button>
HTML
.button-shrink {
color: #65b5f6;
background-color: transparent;
border: 1px solid #65b5f6;
border-radius: 4px;
padding: 0 16px;
cursor: pointer;
transition: all 0.3s ease-in-out;
}
.button-shrink:hover {
transform: scale(0.8);
}
CSS
Результат
Анимация роста кнопки
Код
<button class="button-grow">Submit</button>
HTML
.button-grow {
color: #65b5f6;
background-color: transparent;
border: 1px solid #65b5f6;
border-radius: 4px;
padding: 0 16px;
cursor: pointer;
transition: all 0.3s ease-in-out;
}
.button-grow:hover {
transform: scale(1.1);
}
CSS
Результат
Анимация заполнения кнопки
Код
<button class="animated-fill-button">Submit</button>
HTML
.animated-fill-button {
padding: 20px;
background: #fff;
color: #000;
border: 1px solid #000;
cursor: pointer;
transition: 0.3s all ease-in-out;
}
.animated-fill-button:hover {
background: #000;
color: #fff;
}
CSS
Результат
Анимация качания кнопки
Код
<button class="button-swing">Submit</button>
HTML
.button-swing {
color: #65b5f6;
background-color: transparent;
border: 1px solid #65b5f6;
border-radius: 4px;
padding: 0 16px;
cursor: pointer;
transition: all 0.2s ease-in-out;
}
.button-swing:focus {
animation: swing 1s ease;
animation-iteration-count: 1;
}
@keyframes swing {
15% {
transform: translateX(5px);
}
30% {
transform: translateX(-5px);
}
50% {
transform: translateX(3px);
}
65% {
transform: translateX(-3px);
}
80% {
transform: translateX(2px);
}
100% {
transform: translateX(0);
}
}
CSS
Результат
Анимация границы кнопки
Код
<button class="animated-border-button">Submit</button>
HTML
.animated-border-button {
background-color: #263059;
border: none;
color: #ffffff;
outline: none;
padding: 12px 40px 10px;
position: relative;
}
.animated-border-button:before,
.animated-border-button:after {
border: 0 solid transparent;
transition: all 0.3s;
content: '';
height: 0;
position: absolute;
width: 24px;
}
.animated-border-button:before {
border-top: 2px solid #263059;
right: 0;
top: -4px;
}
.animated-border-button:after {
border-bottom: 2px solid #263059;
bottom: -4px;
left: 0;
}
.animated-border-button:hover:before,
.animated-border-button:hover:after {
width: 100%;
}
CSS
Результат
Увеличить, уменьшить анимацию
Код
<div class="zoom-in-out-box"></div>
HTML
.zoom-in-out-box {
margin: 24px;
width: 50px;
height: 50px;
background: #f50057;
animation: zoom-in-zoom-out 1s ease infinite;
}
@keyframes zoom-in-zoom-out {
0% {
transform: scale(1, 1);
}
50% {
transform: scale(1.5, 1.5);
}
100% {
transform: scale(1, 1);
}
}
CSS
Результат
Ступенчатая анимация
Код
<div class="container">
<input type="checkbox" name="menu" id="menu" class="menu-toggler">
<label for="menu" class="menu-toggler-label">Menu</label>
<ul class="stagger-menu">
<li style="--i: 0">Home</li>
<li style="--i: 1">Pricing</li>
<li style="--i: 2">Account</li>
<li style="--i: 3">Support</li>
<li style="--i: 4">About</li>
</ul>
</div>
HTML
.container {
overflow-x: hidden;
width: 100%;
}
.menu-toggler {
display: none;
}
.menu-toggler-label {
cursor: pointer;
font-size: 20px;
font-weight: bold;
}
.stagger-menu {
list-style-type: none;
margin: 16px 0;
padding: 0;
}
.stagger-menu li {
margin-bottom: 8px;
font-size: 18px;
opacity: 0;
transform: translateX(100%);
transition-property: opacity, transform;
transition-duration: 0.3s;
transition-timing-function: cubic-bezier(0.750, -0.015, 0.565, 1.055);
}
.menu-toggler:checked ~ .stagger-menu li {
opacity: 1;
transform: translateX(0);
transition-delay: calc(0.055s * var(--i));
}
CSS
Результат
CSS
CSS