隨著目前前端頁面的需求不斷提升,有些場景需要漸變背景的元素。本文利用div和css3新屬性,實現(xiàn)了一個背景漸變的按鈕,具體如下:
1.background: linear-gradient 背景為漸變色屬性
2.利用css3中動畫特性animation,實現(xiàn)背景從左至右變化(color_move)
3.為了實現(xiàn)漸變效果,將background的寬度拉長至400%
上代碼:
html:
<div class="btn_demo"> <div class="text">體 驗</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; /* 移動130~150px */ /* 調(diào)用動畫 */ animation-name: arrow_move; /* 持續(xù)時間 */ animation-duration: 1s; /* 無限播放 */ animation-iteration-count: infinite; }
效果如下:
到此這篇關(guān)于利用div+css3實現(xiàn)一個背景漸變的button按鈕的示例代碼的文章就介紹到這了,更多相關(guān)div+css3背景漸變按鈕內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
標(biāo)簽:上海 內(nèi)蒙古 保定 廣安 吳忠 陜西 清遠(yuǎn) 山南
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《利用div+css3實現(xiàn)一個背景漸變的button按鈕的示例代碼》,本文關(guān)鍵詞 利用,div+css3,實現(xiàn),一個,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。