1:様々なボタンを作る
HTMLの記述
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible"content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet"href="style.css">
</head>
<body>
  <divid="container">
  <button class="btn slide-bg">Button</button>
 </div>
</body>
</html>
 
SCSSの記述
$cWhite: white;
$cBlack: black;
#container {
  text-align: center;
}
.btn {
  background-color: $cWhite;
  color: $cBlack;
  border: 1px solid $cBlack;
  padding: 10px 40px;
  margin: 50px 0;
  font-weight: 600;
  cursor: pointer;
  //0.3sかけてアニメーションをする
  transition: all 0.3s;
  &.slide-bg {
    position: relative;
//枠外を非表示
    overflow: hidden;
//前面にする
    z-index: 1;
  &::before {
// 疑似要素のために必要。空のspanを生成している。htmlタグにひとつだけつける
    content: '';
    display: inline-block;
    width: 100%;
    height: 100%;
    background-color: $cBlack;
    position: absolute;
    top: 0;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.3s;
//背面にする    
    z-index: -1;
   }
  &:hover {
   color: $cWhite;
  
  &::before {
   transform: none;
  }
 }
}
}
 
*ポイント
親要素slide-bgの
{ position: relative; overflow: hidden;z-index: 1;}
子要素&::beforeの
{content: ”; position: absolute;}
は重要なので意識しよう
 続きを読む →