想為你的卡片或區塊加上一條別緻的絲帶標籤嗎?本文示範如何以純 CSS3 繪製出立體絲帶效果,讓版面瞬間多了幾分精緻的手作感。
查看效果:
https://hovertree.com/texiao/css3/23/
做法是先在容器內放入一個 .htribbon 元素作為絲帶本體,內部再包一層 .htwrap 與文字。透過 CSS 為絲帶加上折角與陰影,就能營造出布料垂墜的立體感。
HTML 代碼如下:
<div class="httarget">
<div class="htribbon">
<div class="htwrap"><span class="htribbon6">何問起絲帶6</span></div>
</div>
<div class="htcontent">
這裡是內容。
</div>
</div>實際的絲帶樣式定義在外部樣式表 htsidai.css 中,搭配 normalize.css 統一各瀏覽器的預設樣式,讓呈現更一致:
<link rel="stylesheet" type="text/css" href="https://hovertree.com/texiao/css3/23/css/normalize.css" />
<link rel="stylesheet" type="text/css" href="https://hovertree.com/texiao/css3/23/css/htsidai.css">只要替換文字內容,就能把這款絲帶應用在價格標示、「新品」標籤或任何需要强调的區塊上。
來源:何問起