CSS3 製作一個邊框向周圍散開的按鈕效果

來源:互聯網
上載者:User

標籤:

 分析

 主要還是運用CSS3的transition, animation, transform還有漸層背景等特性。

  • 由於按鈕在滑鼠進入時有不同的樣式,所以要對其:hover狀態運用另外的背景樣式
  • 通過對按鈕的:after狀態添加一個內容為空白的元素,並給其一個邊框,這樣在滑鼠進入後我們讓這個隱藏的空元素變大直到淡出,就得到我們看到的效果了

 

 

構建基本按鈕樣式

 做為例子,我們的頁面會很簡單,就放一個a標籤作為按鈕,然後對其寫樣式讓它看起來更像一個按鈕。並定義好:after元素。

 1 <style type="text/css"> 2     .button{ 3     cursor: pointer; 4     text-decoration: none; 5     padding: 10px; 6     color: #fff; 7     border-radius: 10px; 8     position: absolute; 9     top: 100px;10     left: 48%;11     background: linear-gradient(#93c, #50c);12     border:1px solid purple;13     }14     .button:after{15     content: "";16     position: absolute;17     top: 0;18     left: 0;19     width: 100%;20     height: 100%;21     border-radius: 10px;22     opacity: 0;23     border:1px solid purple;24     }25     .button:hover{26         background: linear-gradient(#b5e, #93c);27     }28 </style>29 <body>30     <a class="button" href="javascript:void(0);" >Fake Button</a>31 </body>

 

添加動畫

 首先用keyframes定義動畫

 1 @-webkit-keyframes boom { 2     0% { 3         opacity: 0 4     } 5     5% { 6         opacity: 1 7     } 8     100% { 9         -webkit-transform: scale(1.3);10         transform: scale(1.3);11         opacity: 012     }13 }14 @keyframes boom {15     0% {16         opacity: 017     }18     5% {19         opacity: 120     }21     100% {22         transform: scale(1.3);23         transform: scale(1.3);24         opacity: 025     }26 }

 

再將其運用到按鈕後面隱藏的元素上

 .button:hover:after {     -webkit-animation: boom 0.5s ease;     animation: boom 0.5s ease;}

 

擴充

 另外,我還發現一個jQuery外掛程式jQuery.twinkle專門做這樣的效果,因為是通過js做的,所以原理跟上面的完全不一樣,但這個外掛程式提供的效果豐富,且很炫很有創意,大家可以去欣賞下。下面是一個效果的。

 

 

CSS3 製作一個邊框向周圍散開的按鈕效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.