<!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";
/*塗りから線に変わる*/
.btnchangeline {
display: inline-block;
color: #333;
padding: 10px 30px;
margin: 20px 0;
text-decoration: none;
outline: none;
font-size: max(14px, 2vw);
white-space: nowrap;
width: max(180px, 40vw);
/*線の基点とするためrelativeを指定*/
position: relative;
/*アニメーションの指定*/
transition: all 0.3s ease-in-out;
}
/*線の設定*/
.btnchangeline::before {
content: "";
/*絶対配置で線の位置を決める*/
position: absolute;
bottom: 0;
left: 0;
z-index: 1;
/*線の形状*/
width: 100%;
height: 100%;
border-top: 2.5px solid #666;
border-bottom: 2.5px solid #666;
/*はじめは透過0に*/
opacity: 0;
transform: scale(0, 1);
/*アニメーションの指定*/
transition: all 0.3s;
}
/*背景の設定*/
.btnchangeline::after {
content: "";
/*絶対配置で背景の位置を決める*/
position: absolute;
bottom: 0;
left: 0;
z-index: 1;
/*背景の形状*/
width: 100%;
height: 100%;
background-color: #333;
/*アニメーションの指定*/
transition: all 0.3s;
}
/*hoverした際の背景と線の形状*/
.btnchangeline:hover::before {
opacity: 1; /*不透明に*/
transform: scale(1, 1); /*X方向に線を伸ばす*/
}
.btnchangeline:hover::after {
opacity: 0; /*透過0に*/
transform: scale(0, 1); /*X方向に背景を縮小*/
}
/*テキストの設定*/
.btnchangeline span {
/*テキストを前面に出すためz-indexの値を高く設定*/
position: relative;
z-index: 2;
/*テキストの形状*/
color: #fff;
/*アニメーションの指定*/
transition: all 0.3s;
}
/*hoverした際のテキストの形状*/
.btnchangeline:hover span {
letter-spacing: 2px;
color: #333;
}
/*========= レイアウトのためのCSS ===============*/
body {
width: 100%;
height: 100vh;
vertical-align: middle;
padding: 30px 0;
text-align: center;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-image: linear-gradient(
103.3deg,
rgba(252, 225, 208, 1) 30%,
rgba(255, 173, 214, 1) 55.7%,
rgba(162, 186, 245, 1) 81.8%
);
}
/*ボタンの配置*/
.btn-position {
display: flex;
flex-direction: column;
align-items: center;
}
p {
margin: 0 0 10px 0;
}</style>
</head>
<body>
<body>
<div class="btn-position">
<a href="#" class="btnchangeline">
<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";
/*塗りから線に変わる*/
.btnchangeline {
display: inline-block;
color: #333;
padding: 10px 30px;
margin: 20px 0;
text-decoration: none;
outline: none;
font-size: max(14px, 2vw);
white-space: nowrap;
width: max(180px, 40vw);
/*線の基点とするためrelativeを指定*/
position: relative;
/*アニメーションの指定*/
transition: all 0.3s ease-in-out;
}
/*線の設定*/
.btnchangeline::before {
content: "";
/*絶対配置で線の位置を決める*/
position: absolute;
bottom: 0;
left: 0;
z-index: 1;
/*線の形状*/
width: 100%;
height: 100%;
border-top: 2.5px solid #666;
border-bottom: 2.5px solid #666;
/*はじめは透過0に*/
opacity: 0;
transform: scale(0, 1);
/*アニメーションの指定*/
transition: all 0.3s;
}
/*背景の設定*/
.btnchangeline::after {
content: "";
/*絶対配置で背景の位置を決める*/
position: absolute;
bottom: 0;
left: 0;
z-index: 1;
/*背景の形状*/
width: 100%;
height: 100%;
background-color: #333;
/*アニメーションの指定*/
transition: all 0.3s;
}
/*hoverした際の背景と線の形状*/
.btnchangeline:hover::before {
opacity: 1; /*不透明に*/
transform: scale(1, 1); /*X方向に線を伸ばす*/
}
.btnchangeline:hover::after {
opacity: 0; /*透過0に*/
transform: scale(0, 1); /*X方向に背景を縮小*/
}
/*テキストの設定*/
.btnchangeline span {
/*テキストを前面に出すためz-indexの値を高く設定*/
position: relative;
z-index: 2;
/*テキストの形状*/
color: #fff;
/*アニメーションの指定*/
transition: all 0.3s;
}
/*hoverした際のテキストの形状*/
.btnchangeline:hover span {
letter-spacing: 2px;
color: #333;
}
/*========= レイアウトのためのCSS ===============*/
body {
width: 100%;
height: 100vh;
vertical-align: middle;
padding: 30px 0;
text-align: center;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-image: linear-gradient(
103.3deg,
rgba(252, 225, 208, 1) 30%,
rgba(255, 173, 214, 1) 55.7%,
rgba(162, 186, 245, 1) 81.8%
);
}
/*ボタンの配置*/
.btn-position {
display: flex;
flex-direction: column;
align-items: center;
}
p {
margin: 0 0 10px 0;
}
/*
外部依存 CSS (このデモは下記の CSS にも依存します):
- https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css
*/