<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style>@charset "utf-8";
/*== 背景共通設定 */
body {
width: 100%;
height: 100vh;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-image: url("/wp-content/uploads/demos/_assets/img_06.jpg");
object-fit: cover;
}
/*== ボタン共通設定 */
.btn {
/*アニメーションの起点とするためrelativeを指定*/
position: relative;
overflow: hidden;
/*ボタンの形状*/
text-decoration: none;
border: 1px solid rgba(255, 255, 255, 0.18);
display: inline-block;
padding: 20px 0;
margin: 10px 0;
text-align: center;
outline: none;
transition: ease 0.2s; /*アニメーションの指定*/
width: clamp(240px, 50vw, 500px); /*ボタンの横幅を全て統一*/
background-color: rgba(255, 255, 255, 0.3);
backdrop-filter: blur(6.5px);
-webkit-backdrop-filter: blur(6.5px);
box-shadow: 0px 6px 15px 0px rgba(142, 142, 142, 0.19);
-webkit-box-shadow: 0px 6px 15px 0px rgba(142, 142, 142, 0.19);
border-radius: 12px;
-webkit-border-radius: 12px;
color: rgba(255, 255, 255, 0.898);
}
/*ボタンの配置*/
.btn-position {
display: flex;
flex-direction: column;
align-items: center;
}
/*ボタン内spanの形状*/
.btn span {
position: relative;
z-index: 3; /*z-indexの数値をあげて文字を背景よりも手前に表示*/
color: #333;
font-size: clamp(0.8rem, 2vw, 1rem);
}
.btn:hover span {
color: #fff;
}
/* ==== 背景が流れる(左から右) ==== */
.bgleft:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.6s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(0, 1);
transform-origin: right top;
}
/*hoverした際の形状*/
.bgleft:hover:before {
transform-origin: left top;
transform: scale(1, 1);
}
/* ==== 背景が流れる(右から左) ==== */
.bgright:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.6s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(0, 1);
transform-origin: left top;
}
/*hoverした際の形状*/
.bgright:hover:before {
transform-origin: right top;
transform: scale(1, 1);
}
/* ==== 背景が流れる(上から下) ==== */
.bgtop:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 0;
/*アニメーション*/
transition: 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
}
/*hoverした際の形状*/
.bgtop:hover:before {
height: 100%;
background-color: rgba(90, 150, 255, 0.5);*
}
/* ==== 背景が流れる(下から上) ==== */
.bgbottom:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
bottom: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 0;
/*アニメーション*/
transition: 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
}
/*hoverした際の形状*/
.bgbottom:hover:before {
height: 100%;
background: rgba(90, 150, 255, 0.5);
}
/* ==== 背景が流れる(中央から横全体) ==== */
.bgcenterx:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(0, 1);
transform-origin: top; /* bottomでも同じです */
}
/*hoverした際の形状*/
.bgcenterx:hover:before {
transform: scale(1, 1);
}
/* ==== 背景が流れる(中央から縦全体) ==== */
.bgcentery:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(1, 0);
transform-origin: center;
}
/*hoverした際の形状*/
.bgcentery:hover:before {
transform: scale(1, 1);
}
/* ==== 背景が流れる(中央から外) ==== */
.bgcenterout:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(0, 0);
transform-origin: center;
}
/*hoverした際の形状*/
.bgcenterout:hover:before {
transform: scale(1, 1);
}
/* ==== 背景が流れる(斜め) ==== */
.bgskew::before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: -130%;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 120%;
height: 100%;
transform: skewX(-25deg);
}
/*hoverした時のアニメーション*/
.bgskew:hover::before {
animation: skewanime 0.7s forwards; /*アニメーションの名前と速度を定義*/
}
@keyframes skewanime {
0% {
right: -10%; /*画面の見えていない左から右へ移動する終了地点*/
}
100% {
left: 110%; /*画面の見えていない左から右へ移動する終了地点*/
}
}
/*========= レイアウトのためのCSS ===============*/
body {
vertical-align: middle;
padding: 20px 0;
text-align: center;
}
p {
margin: 0 0 10px 0;
}</style>
</head>
<body>
<body>
<div class="btn-position">
<a href="#" class="btn bgleft">
<span>背景が流れる(左から右)</span>
</a>
<a href="#" class="btn bgright">
<span>背景が流れる(右から左)</span>
</a>
<a href="#" class="btn bgtop">
<span>背景が流れる(上から下)</span>
</a>
<a href="#" class="btn bgbottom">
<span>背景が流れる(下から上)</span>
</a>
<a href="#" class="btn bgcenterx">
<span>背景が流れる(中央から横全体)</span>
</a>
<a href="#" class="btn bgcentery">
<span>背景が流れる(中央から縦全体)</span>
</a>
<a href="#" class="btn bgcenterout">
<span>背景が流れる(中央から外)</span>
</a>
<a href="#" class="btn bgskew">
<span>背景が流れる(斜め)</span>
</a>
</div>
<script>
</script>
</body>
</html>
/*
外部依存 CSS:
- https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css
*/
@charset "utf-8";
/*== 背景共通設定 */
body {
width: 100%;
height: 100vh;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-image: url("/wp-content/uploads/demos/_assets/img_06.jpg");
object-fit: cover;
}
/*== ボタン共通設定 */
.btn {
/*アニメーションの起点とするためrelativeを指定*/
position: relative;
overflow: hidden;
/*ボタンの形状*/
text-decoration: none;
border: 1px solid rgba(255, 255, 255, 0.18);
display: inline-block;
padding: 20px 0;
margin: 10px 0;
text-align: center;
outline: none;
transition: ease 0.2s; /*アニメーションの指定*/
width: clamp(240px, 50vw, 500px); /*ボタンの横幅を全て統一*/
background-color: rgba(255, 255, 255, 0.3);
backdrop-filter: blur(6.5px);
-webkit-backdrop-filter: blur(6.5px);
box-shadow: 0px 6px 15px 0px rgba(142, 142, 142, 0.19);
-webkit-box-shadow: 0px 6px 15px 0px rgba(142, 142, 142, 0.19);
border-radius: 12px;
-webkit-border-radius: 12px;
color: rgba(255, 255, 255, 0.898);
}
/*ボタンの配置*/
.btn-position {
display: flex;
flex-direction: column;
align-items: center;
}
/*ボタン内spanの形状*/
.btn span {
position: relative;
z-index: 3; /*z-indexの数値をあげて文字を背景よりも手前に表示*/
color: #333;
font-size: clamp(0.8rem, 2vw, 1rem);
}
.btn:hover span {
color: #fff;
}
/* ==== 背景が流れる(左から右) ==== */
.bgleft:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.6s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(0, 1);
transform-origin: right top;
}
/*hoverした際の形状*/
.bgleft:hover:before {
transform-origin: left top;
transform: scale(1, 1);
}
/* ==== 背景が流れる(右から左) ==== */
.bgright:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.6s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(0, 1);
transform-origin: left top;
}
/*hoverした際の形状*/
.bgright:hover:before {
transform-origin: right top;
transform: scale(1, 1);
}
/* ==== 背景が流れる(上から下) ==== */
.bgtop:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 0;
/*アニメーション*/
transition: 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
}
/*hoverした際の形状*/
.bgtop:hover:before {
height: 100%;
background-color: rgba(90, 150, 255, 0.5);*
}
/* ==== 背景が流れる(下から上) ==== */
.bgbottom:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
bottom: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 0;
/*アニメーション*/
transition: 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
}
/*hoverした際の形状*/
.bgbottom:hover:before {
height: 100%;
background: rgba(90, 150, 255, 0.5);
}
/* ==== 背景が流れる(中央から横全体) ==== */
.bgcenterx:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(0, 1);
transform-origin: top; /* bottomでも同じです */
}
/*hoverした際の形状*/
.bgcenterx:hover:before {
transform: scale(1, 1);
}
/* ==== 背景が流れる(中央から縦全体) ==== */
.bgcentery:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(1, 0);
transform-origin: center;
}
/*hoverした際の形状*/
.bgcentery:hover:before {
transform: scale(1, 1);
}
/* ==== 背景が流れる(中央から外) ==== */
.bgcenterout:before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: 0;
z-index: 2;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 100%;
height: 100%;
/*アニメーション*/
transition: transform 0.3s cubic-bezier(0.8, 0, 0.2, 1) 0s;
transform: scale(0, 0);
transform-origin: center;
}
/*hoverした際の形状*/
.bgcenterout:hover:before {
transform: scale(1, 1);
}
/* ==== 背景が流れる(斜め) ==== */
.bgskew::before {
content: "";
/*絶対配置で位置を指定*/
position: absolute;
top: 0;
left: -130%;
/*色や形状*/
background: rgba(90, 150, 255, 0.5);
width: 120%;
height: 100%;
transform: skewX(-25deg);
}
/*hoverした時のアニメーション*/
.bgskew:hover::before {
animation: skewanime 0.7s forwards; /*アニメーションの名前と速度を定義*/
}
@keyframes skewanime {
0% {
right: -10%; /*画面の見えていない左から右へ移動する終了地点*/
}
100% {
left: 110%; /*画面の見えていない左から右へ移動する終了地点*/
}
}
/*========= レイアウトのためのCSS ===============*/
body {
vertical-align: middle;
padding: 20px 0;
text-align: center;
}
p {
margin: 0 0 10px 0;
}
/*
外部依存 CSS (このデモは下記の CSS にも依存します):
- https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css
*/