利用div+css3實(shí)現(xiàn)一個(gè)背景漸變的button按鈕的示例代碼

隨著目前前端頁(yè)面的需求不斷提升,有些場(chǎng)景需要漸變背景的元素。本文利用div和css3新屬性,實(shí)現(xiàn)了一個(gè)背景漸變的按鈕,具體如下:
1.background: linear-gradient 背景為漸變色屬性
2.利用css3中動(dòng)畫特性animation,實(shí)現(xiàn)背景從左至右變化(color_move)
3.為了實(shí)現(xiàn)漸變效果,將background的寬度拉長(zhǎng)至400%
上代碼:
html:
<div class="btn_demo"> <div class="text">體 驗(yàn)</div> <div class="arrow">»</div> </div>
css:
@keyframes arrow_move { /* 開始狀態(tài) */ 0% { left: 130px; } /* 結(jié)束狀態(tài) */ 100% { left: 140px; } } @keyframes color_move { /* 開始狀態(tài) */ 0% { background-position: 0% 0%; /* 水平位置 垂直位置 */ } 50% { background-position: 50% 0%; } /* 結(jié)束狀態(tài) */ 100% { background-position: 100% 0%; } } .btn_demo { width:180px; height:60px; border-radius: 10px; position: relative; background: linear-gradient( 90deg, #373d42 0%, #2679dd 50%, #373d42 100%); background-size: 400% 100%; animation: color_move 5s infinite ease-in-out alternate; cursor: pointer; } .btn_demo:hover { background: #2679dd; } .btn_demo:active { background: #373d42; } .btn_demo > .text { /* background: yellow; */ width: 50px; text-align: center; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); font-size: 20px; color: #fff; font-weight: bold; } .btn_demo > .arrow { /* background: green; */ width: 20px; text-align: center; position: absolute; font-size: 30px; color: #fff; top: 46%; transform: translateY(-50%); left: 130px; /* 移動(dòng)130~150px */ /* 調(diào)用動(dòng)畫 */ animation-name: arrow_move; /* 持續(xù)時(shí)間 */ animation-duration: 1s; /* 無(wú)限播放 */ animation-iteration-count: infinite; }
效果如下:
到此這篇關(guān)于利用div+css3實(shí)現(xiàn)一個(gè)背景漸變的button按鈕的示例代碼的文章就介紹到這了,更多相關(guān)div+css3背景漸變按鈕內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
- 是一段基于純CSS3制作的彩色漸變按鈕懸停動(dòng)畫設(shè)計(jì),圓角按鈕懸停交互特效代碼,非常有意思,歡迎有興趣的朋友前來(lái)下載使用2020-10-09
- 純css3制作彩色漸變的按鈕懸停動(dòng)畫設(shè)計(jì),圓角按鈕懸停ui交互特效,喜歡的朋友快來(lái)下載源碼吧2020-09-08
css3實(shí)現(xiàn)的鼠標(biāo)懸浮按鈕發(fā)光漸變動(dòng)畫特效源碼
是一段基于CSS3實(shí)現(xiàn)的鼠標(biāo)懸停按鈕炫彩動(dòng)畫特效源碼,將鼠標(biāo)放在按鈕上后,按鈕會(huì)持續(xù)出現(xiàn)流光漸變效果,非常有意思,歡迎有興趣的朋友前來(lái)了解使用2020-08-28CSS3點(diǎn)擊按鈕實(shí)現(xiàn)背景漸變動(dòng)畫效果
這篇文章給大家介紹的是,利用CSS3實(shí)現(xiàn)當(dāng)點(diǎn)擊按鈕的時(shí)候,按鈕的背景是漸變動(dòng)畫的效果,實(shí)現(xiàn)后的效果非常好,開發(fā)的時(shí)候利用這種效果的按鈕會(huì)給用戶一種非常酷炫的感受,感2016-10-19純CSS3實(shí)現(xiàn)的顏色漸變的一級(jí)橫向?qū)Ш桨粹o菜單效果
無(wú)需任何JS代碼即可實(shí)現(xiàn)顏色漸變的按鈕式菜單,菜單為一級(jí)橫向?qū)Ш?/div> 2013-07-01純CSS3 gradient屬性制作36種漂亮的html網(wǎng)頁(yè)漸變按鈕樣式
36種漂亮的CSS3 gradient屬性制作的html網(wǎng)頁(yè)漸變按鈕樣式,非常不錯(cuò),喜歡的朋友朋友快來(lái)下載源碼吧2020-10-14最新評(píng)論