<!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";
/*矢印が右に移動して背景がつく*/
.btnarrow {
/*矢印の基点とするためrelativeを指定*/
position: relative;
/*ボタンの形状*/
background: #333;
padding: 5px 60px 5px 30px;
margin: 20px 0;
display: inline-block;
text-align: center;
transition: all 0.2s linear;
color: #fff;
text-decoration: none;
border: transparent 2px solid;
outline: none;
font-size: max(14px, 2vw);
white-space: nowrap;
width: max(150px, 40vw);
/*アニメーションの指定*/
transition: all 0.2s linear;
}
.btnarrow:hover {
background: #fff;
color: #333;
border-color: #333;
}
/*矢印と線の形状*/
.btnarrow:before {
content: "";
/*絶対配置で線の位置を決める*/
position: absolute;
top: 50%;
right: 20px;
/*線の形状*/
width: 20px;
height: 1px;
background: #fff;
}
.btnarrow::after {
content: "";
/*絶対配置で矢印の位置を決める*/
position: absolute;
top: 40%;
right: 12px;
/*矢印の形状*/
border: 4px solid transparent;
border-top-width: 4px;
border-bottom-width: 4px;
border-left-color: #fff;
/*アニメーションの指定*/
transition: all 0.2s linear;
}
/*hoverした際の矢印の形状*/
.btnarrow:hover::before {
background: #333;
right: 25px;
}
.btnarrow:hover::after {
border-left-color: #333;
right: 20px;
}
/*========= レイアウトのための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;
justify-content: center;
}
p {
margin: 0 0 10px 0;
}</style>
</head>
<body>
<body>
<div class="btn-position">
<a href="#" class="btnarrow">矢印が縮む</a>
</div>
<script>
</script>
</body>
</html>
/*
外部依存 CSS:
- https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css
*/
@charset "utf-8";
/*矢印が右に移動して背景がつく*/
.btnarrow {
/*矢印の基点とするためrelativeを指定*/
position: relative;
/*ボタンの形状*/
background: #333;
padding: 5px 60px 5px 30px;
margin: 20px 0;
display: inline-block;
text-align: center;
transition: all 0.2s linear;
color: #fff;
text-decoration: none;
border: transparent 2px solid;
outline: none;
font-size: max(14px, 2vw);
white-space: nowrap;
width: max(150px, 40vw);
/*アニメーションの指定*/
transition: all 0.2s linear;
}
.btnarrow:hover {
background: #fff;
color: #333;
border-color: #333;
}
/*矢印と線の形状*/
.btnarrow:before {
content: "";
/*絶対配置で線の位置を決める*/
position: absolute;
top: 50%;
right: 20px;
/*線の形状*/
width: 20px;
height: 1px;
background: #fff;
}
.btnarrow::after {
content: "";
/*絶対配置で矢印の位置を決める*/
position: absolute;
top: 40%;
right: 12px;
/*矢印の形状*/
border: 4px solid transparent;
border-top-width: 4px;
border-bottom-width: 4px;
border-left-color: #fff;
/*アニメーションの指定*/
transition: all 0.2s linear;
}
/*hoverした際の矢印の形状*/
.btnarrow:hover::before {
background: #333;
right: 25px;
}
.btnarrow:hover::after {
border-left-color: #333;
right: 20px;
}
/*========= レイアウトのための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;
justify-content: center;
}
p {
margin: 0 0 10px 0;
}
/*
外部依存 CSS (このデモは下記の CSS にも依存します):
- https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css
*/