首頁 網頁資源RESOURCES CSS
互動式CSS按鈕動畫一點都不難!Html + CSS 實作範例,一試就上手

互動式CSS按鈕動畫一點都不難!Html + CSS 實作範例,一試就上手

2021.05.18
分享一些簡單的按鈕動畫
變深
展示
按鈕
HTML
複製已複製
<div class="shape-ex1">按鈕</div>
CSS
複製已複製
.shape-ex1{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    transition: all .3s linear;
}
.shape-ex1:hover{
    background-color: #000;
    color: #fff;
}
變淺
展示
按鈕
HTML
複製已複製
<div class="shape-ex2">按鈕</div>
CSS
複製已複製
.shape-ex2{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #fff;
    background-color: #000;
    transition: all .3s linear;
}
.shape-ex2:hover{
    background-color: #666;
}
由左向右填滿
展示

按鈕

HTML
複製已複製
<div class="shape-ex3"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex3{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    position: relative;
    transition: all .3s linear;
}
.shape-ex3 > p{
    position: relative;
    z-index: 1;
}
.shape-ex3::before{
    content: "";
    width: 0%;
    height: 100%;
    display: block;
    background-color: #000;
    position: absolute;
    top: 0;
    left: 0;
    transition: all .3s ease;
}
.shape-ex3:hover{
    color: #fff;
}
.shape-ex3:hover::before{
    width: 100%;
}
由右向左填滿
展示

按鈕

HTML
複製已複製
<div class="shape-ex4"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex4{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    position: relative;
    transition: all .3s linear;
}
.shape-ex4 > p{
    position: relative;
    z-index: 1;
}
.shape-ex4::before{
    content: "";
    width: 0%;
    height: 100%;
    display: block;
    background-color: #000;
    position: absolute;
    top: 0;
    right: 0;
    transition: all .3s ease;
}
.shape-ex4:hover{
    color: #fff;
}
.shape-ex4:hover::before{
    width: 100%;
}
由上向下填滿
展示

按鈕

HTML
複製已複製
<div class="shape-ex5"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex5{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    position: relative;
    transition: all .3s linear;
}
.shape-ex5 > p{
    position: relative;
    z-index: 1;
}
.shape-ex5::before{
    content: "";
    width: 100%;
    height: 0%;
    display: block;
    background-color: #000;
    position: absolute;
    top: 0;
    left: 0;
    transition: all .3s ease;
}
.shape-ex5:hover{
    color: #fff;
}
.shape-ex5:hover::before{
    height: 100%;
}
由下向上填滿
展示

按鈕

HTML
複製已複製
<div class="shape-ex6"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex6{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    position: relative;
    transition: all .3s linear;
}
.shape-ex6 > p{
    position: relative;
    z-index: 1;
}
.shape-ex6::before{
    content: "";
    width: 100%;
    height: 0%;
    display: block;
    background-color: #000;
    position: absolute;
    bottom: 0;
    left: 0;
    transition: all .3s ease;
}
.shape-ex6:hover{
    color: #fff;
}
.shape-ex6:hover::before{
    height: 100%;
}
由右上向左下填滿
展示

按鈕

HTML
複製已複製
<div class="shape-ex7"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex7{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    position: relative;
    transition: all .3s linear;
}
.shape-ex7 > p{
    position: relative;
    z-index: 1;
}
.shape-ex7::before{
    content: "";
    width: 0%;
    height: 0%;
    display: block;
    background-color: #000;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    transition: all .3s ease;
}
.shape-ex7:hover{
    color: #fff;
}
.shape-ex7:hover::before{
    width: 100%;
    height: 100%;
    opacity: 1;
}
由左上向右下填滿
展示

按鈕

HTML
複製已複製
<div class="shape-ex8"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex8{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    position: relative;
    transition: all .3s linear;
}
.shape-ex8 > p{
    position: relative;
    z-index: 1;
}
.shape-ex8::before{
    content: "";
    width: 0%;
    height: 0%;
    display: block;
    background-color: #000;
    position: absolute;
    top: 0;
    right: 0;
    opacity: 0;
    transition: all .3s ease;
}
.shape-ex8:hover{
    color: #fff;
}
.shape-ex8:hover::before{
    width: 100%;
    height: 100%;
    opacity: 1;
}
由右下向左上填滿
展示

按鈕

HTML
複製已複製
<div class="shape-ex9"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex9{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    position: relative;
    transition: all .3s linear;
}
.shape-ex9 > p{
    position: relative;
    z-index: 1;
}
.shape-ex9::before{
    content: "";
    width: 0%;
    height: 0%;
    display: block;
    background-color: #000;
    position: absolute;
    bottom: 0;
    left: 0;
    opacity: 0;
    transition: all .3s ease;
}
.shape-ex9:hover{
    color: #fff;
}
.shape-ex9:hover::before{
    width: 100%;
    height: 100%;
    opacity: 1;
}
由左下向右上填滿
展示

按鈕

HTML
複製已複製
<div class="shape-ex10"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex10{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    border: 1px solid #000;
    position: relative;
    transition: all .3s linear;
}
.shape-ex10 > p{
    position: relative;
    z-index: 1;
}
.shape-ex10::before{
    content: "";
    width: 0%;
    height: 0%;
    display: block;
    background-color: #000;
    position: absolute;
    bottom: 0;
    right: 0;
    opacity: 0;
    transition: all .3s ease;
}
.shape-ex10:hover{
    color: #fff;
}
.shape-ex10:hover::before{
    width: 100%;
    height: 100%;
    opacity: 1;
}
線條框
展示

按鈕

HTML
複製已複製
<div class="shape-ex11"><p>按鈕</p></div>
CSS
複製已複製
.shape-ex11{
    width: 150px;
    height: 40px;
    display: block;
    text-align: center;
    cursor: pointer;
    line-height: 40px;
    color: #000;
    background-color: transparent;
    position: relative;
    transition: all .3s linear;
}
.shape-ex11 > p{
    position: relative;
    z-index: 1;
}
.shape-ex11::before{
    content: "";
    width: 20px;
    height: 20px;
    display: block;
    box-sizing: border-box;
    border-top: 1px solid #000;
    border-left: 1px solid #000;
    position: absolute;
    top: 0;
    left: 0;
    transition: all .3s linear;
}
.shape-ex11::after{
    content: "";
    width: 20px;
    height: 20px;
    display: block;
    box-sizing: border-box;
    border-bottom: 1px solid #000;
    border-right: 1px solid #000;
    position: absolute;
    bottom: 0;
    right: 0;
    transition: all .3s linear;
}
.shape-ex11:hover::before,
.shape-ex11:hover::after{
    width: 100%;
    height: 100%;
}
其他類別