HTML5+CSS3小實例:水波紋按鈕效果

實例:水波紋按鈕效果
技術棧:HTML+CSS
效果:

源碼:
【html】

<!DOCTYPE html>
<html>
 
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
 
    <title>水波紋效果按鈕</title>
    <link rel="stylesheet" href="../css/56.css">
</head>
 
<body>
    <div class="btn-box">
        <div class="btn">
            <span>點贊</span>
            <div class="wave"></div>
        </div>
        <div class="btn">
            <span>關注</span>
            <div class="wave"></div>
        </div>
        <div class="btn">
            <span>收藏</span>
            <div class="wave"></div>
        </div>
        <div class="btn">
            <span>轉發(fā)</span>
            <div class="wave"></div>
        </div>
    </div>
</body>
 
</html>

【css】

*{
    /* 初始化 */
    margin: 0;
    padding: 0;
}
body{
    /* 100%窗口高度 */
    height: 100vh;
    /* 彈性布局 居中 */
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(200deg,#e7f0fd,#accbee);
}
.btn-box{
    width: 500px;
    /* 彈性布局 */
    display: flex;
    /* 橫向排列 */
    flex-direction: row;
    /* 允許換行 */
    flex-wrap: wrap;
    /* 平均分配寬度給每一個子元素 */
    justify-content: space-around;
}
.btn{
    /* 相對定位 */
    position: relative;
    width: 200px;
    height: 60px;
    line-height: 60px;
    text-align: center;
    margin: 20px 0;
    font-size: 18px;
    /* 字間距 */
    letter-spacing: 4px;
    color: #00aeff;
    border: 2px solid #00aeff;
    cursor: pointer;
    /* 溢出隱藏 */
    overflow: hidden;
}
.btn span{
    position: relative;
    z-index: 1;
    /* 動畫過渡 */
    transition: 1s;
}
.btn .wave{
    /* 絕對定位 */
    position: absolute;
    /* 計算top */
    top: calc(100% + 22px);
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #00aeff;
    transition: 1s;
}
.btn .wave::before{
    content: "";
    position: absolute;
    top: -22px;
    left: 0;
    width: 100%;
    height: 22px;
    background-image: url("../images/wave.png");
    /* 執(zhí)行動畫:動畫名 時長 線性的 無限次播放 */
    animation: animate 0.5s linear infinite;
}
.btn:hover .wave{
    top: 0;
}
.btn:hover span{
    color: #fff;
}
 
/* 定義動畫 */
@keyframes animate {
    0%{
        /* 改變背景X軸定位和Y軸定位 */
        background-position-x: 0;
        background-position-y: -22px;
    }
    100%{
        background-position-x: 118px;
        background-position-y: -22px;
    }
}

【圖片素材】
https://www.aliyundrive.com/s/CY2SyembN9y

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容