CSS 文字底線效果


用 box-shadow 實現


.text{
    text-decoration: none;
    box-shadow:0 -1px 0 #2858aa inset;
    transition:box-shadow .2s ease-in-out;
}
.text:hover{
    box-shadow:0 -1px 0 rgba(0,0,0,0) inset,
               0 3px 0 #2858aa;
    transition:box-shadow .2s ease-in-out;
}

結果如下

HOVER ME

用 psudo element 和 scaleX 實現


.text {
    text-decoration: none;
    position: relative;
}
.text::before{
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background-color: #6ac7ef;
    transform-origin: bottom right;
    transform: scaleX(0);
    transition: transform .3s ease;
}
.text:hover::before{
    transform-origin: bottom left;
    transform: scaleX(1);
}

效果如下

HOVER ME

留言

這個網誌中的熱門文章

用CSS的 min() max() 與vw,設計有極限值的RWD響應式文字

10 steps、「ライブ会場を沸らせる、フロアを沸かす」ミーム動画の作り方 (Viggle AI)

運用資料層 dataLayer.push 建立 GTM 自訂事件