<div class="layout">
<!-- ここからボタンのHTML -->
<!-- ボタンの背景が上から現れる -->
<div class="button-01">
<a href="#"><span>ボタン</span></a>
</div>
<!-- ボタンの背景が下から現れる -->
<div class="button-02">
<a href="#"><span>ボタン</span></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 */
//背景が上から現れるボタン
.button-01 {
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;
transition: all 0.3s;
span {
position: relative;
}
&::before {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: #5cc0ef;
transform: translateY(-100%);
transition: all 0.3s;
}
&:hover {
color: #fff;
&::before {
transform: translateY(0);
}
}
}
}
//背景が下から現れるボタン
.button-02 {
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;
transition: all 0.3s;
span {
position: relative;
}
&::before {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: #5cc0ef;
transform: translateY(100%);
transition: all 0.3s;
}
&:hover {
color: #fff;
&::before {
transform: translateY(0);
}
}
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.