萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> Div CSS 教學

CSS3 :before/:after 偽元素打造圓形按鈕(陰影、發光、動畫)

善用 ::before/::after 可在單一 HTML 元素上疊加多層裝飾,打造豐富視覺效果。本文示範兩顆圓形按鈕(註冊/登入),含陰夏、內陰影、文字、hover 動畫,並引入 prefixfree.js 自動補全前綴。

HTML 結構

<div class="bt">
  <div class="button"></div>
  <div class="button2"></div>
  <div style="clear:both"></div>
</div>

核心 CSS(節錄)

.bt { margin:100px auto; width:350px; opacity:0; border-top/bottom:1px solid #C5C5C5;
  box-shadow: 0 1px 0 #F6F6F6, 0 1px 0 #F6F6F6 inset; transition: all 0.5s ease-in; }

.button, .button2 {
  float:left/right; margin:50px auto; width:100px; height:100px; border-radius:50%;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.4); background:#FFF; position:relative;
  transition: all 0.5s ease-in; cursor:pointer;
}

/* 內陰影圓環 */
.button:before, .button2:before {
  content:""; position:relative; left:-15px; top:-15px; z-index:-1;
  width:130px; height:130px; border-radius:65px; background:#ddd;
  box-shadow: inset 2px 2px 4px rgba(0,0,0,0.4);
}

/* 文字 */
.button:after  { content:"註冊"; color:#09F; font-size:20px; line-height:100px; position:absolute; top:0; width:100%; text-align:center; display:block; }
.button2:after { content:"登入"; color:#A0D989; word-spacing:25px; }

效果預覽

圓形按鈕效果

線上按鈕生成工具推薦

  1. Live Tools — 全能 UI 生成器(按鈕、表單、Icon、Ribbons)
  2. CSS3 Button Generator — 簡易雙狀態按鈕
  3. Button Generator — 圖片級真實感按鈕
  4. Webarti CSS3 Button Maker — 豐富預設樣式,所見即所得

掌握偽元素疊加技巧,單標籤即可構建複雜 UI,HTML 保持極簡語意化。

copyright © 萬盛學電腦網 all rights reserved