善用 ::before/::after 可在單一 HTML 元素上疊加多層裝飾,打造豐富視覺效果。本文示範兩顆圓形按鈕(註冊/登入),含陰夏、內陰影、文字、hover 動畫,並引入 prefixfree.js 自動補全前綴。
<div class="bt">
<div class="button"></div>
<div class="button2"></div>
<div style="clear:both"></div>
</div>
.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; }

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