<div class="layout">
<!-- ここからボタンのHTML -->
<div class="button">
<a href="#">ボタン</a>
</div>
<!-- ここまでボタンのHTML -->
</div>
/* ここはレイアウトなのでボタンとは関係ない */
* {
margin: 0;
}
.layout {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 50px;
width: 100%;
height: 100vh;
}
/* ここからボタンのCSS */
@keyframes left-circle {
0% {
left: -20px;
width: 20px;
height: 20px;
}
50% {
left: 50%;
width: 20px;
height: 20px;
}
100% {
left: 50%;
width: calc(240px * 1.5);
height: calc(240px * 1.5);
}
}
@keyframes right-circle {
0% {
right: -20px;
width: 20px;
height: 20px;
}
50% {
right: 50%;
width: 20px;
height: 20px;
}
100% {
right: 50%;
width: calc(240px * 1.5);
height: calc(240px * 1.5);
}
}
.button {
a {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 240px;
height: 50px;
font-size: 16px;
text-decoration: none;
color: #5cc0ef;
border: 1px solid #5cc0ef;
overflow: hidden;
//hoverを辞めたときのアニメーション速度
transition: all 0.5s;
&::before,
&::after {
content: '';
position: absolute;
z-index: -1;
top: 50%;
width: 20px;
height: 20px;
background-color: #5cc0ef;
border-radius: 50%;
transform: translate(-50%, -50%);
}
&::before {
left: -20px;
}
&::after {
right: -20px;
transform: translate(50%, -50%);
}
&:hover {
color: #fff;
//hoverしたときのアニメーション速度
transition: all 0.4s 0.4s;
&::before {
animation: left-circle 0.8s both alternate;
}
&::after {
animation: right-circle 0.8s both alternate;
}
}
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.