天天看點

【每日一練】68—CSS實作一組漸變按鈕動畫效果

【每日一練】68—CSS實作一組漸變按鈕動畫效果

在之前,我們也練習過一些按鈕動畫的效果,今天我們再來練習一組CSS實作的按鈕動畫效果,下面是今天練習的最終效果:

【每日一練】68—CSS實作一組漸變按鈕動畫效果

接下來,我們再來看一下這個案例的源碼。

HTML代碼:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>【每日一練】68—CSS實作一組漸變按鈕動畫效果</title>
</head>
<body>
  <div class="container">
    <a href="https://www.webqdkf.com/">首頁</a>
    <a href="https://www.webqdkf.com/qdkf/">前端技術</a>
    <a href="https://www.webqdkf.com/code/">源碼案例</a>
    <a href="https://www.webqdkf.com/mb/">建站模闆</a>
    <a href="http://www.aierweisi.com">建站主機</a>
    <a href="https://www.webqdkf.com/">資源導航</a>
  </div>
</body>
</html>      

CSS代碼:

*
{
  margin: 0;
  padding: 0;
  font-family: 'Poppins', sans-serif;
}
body
{
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}
.container
{
  width: 1200px;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}
.container a
{
  position: relative;
  display: inline-block;
  padding: 10px 30px;
  margin: 20px;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 16px;
  color: #fff;
  transition: 0.5s;
}
.container a:nth-child(1)
{
  background: linear-gradient(to right,#C6FFDD, #FBD786,#f64f59);
  background-size: 200%;
}
.container a:nth-child(2)
{
  background: linear-gradient(to right,#7F7FD5, #86A8E7,#91EAE4);
  background-size: 200%;
}
.container a:nth-child(3)
{
  background: linear-gradient(to right, #12c2e9, #c471ed, #f64f59);
  background-size: 200%;
}
.container a:nth-child(4)
{
  background: linear-gradient(to right, #4481eb, #04befe, #4481eb);
  background-size: 200%;
}
.container a:nth-child(5)
{
  background: linear-gradient(to right, #1E9600, #FFF200, #FF0000);
  background-size: 200%;
}
.container a:nth-child(6)
{
  background: linear-gradient(to right, #fdfc47, #24fe41, #fdfc47);
  background-size: 200%;
}
.container a:hover
{
  background-position-x: 100%;
  transform: translateY(-15px);
}
.container a:after
{
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: rgba(255,255,255,.2);
}
.container a:before
{
  content: '';
  position: absolute;
  bottom: 0px;
  left: 5%;
  width: 90%;
  height: 4px;
  background: rgba(0,0,0,0.2);
  border-radius: 50%;
  transform: scale(0);
  transition: 0.5s;
  filter: blur(5px);
  z-index: -1;
}
.container a:hover:before
{
  transform: scale(1);
  bottom: -15px;
}      

寫在最後

以上就是今天【每日一練】的全部内容,希望今天的小練習對你有用,如果你覺得有幫助的話,請點贊我,并将它分享給你身邊做開發的朋友,也許能夠幫助到他。

我是楊小愛,我們明天見。