使用CSS建立一個圖片角標

來源:互聯網
上載者:User

標籤:

角標是一個給某元素標明“New”,"Popular"等以表示強調的好方法,常應用於圖片。下面就利用CSS和HTML實現了圖片的角標效果。 建立兩個元素,一個用於建立角標,一個用於角標內的文本。 
<p><span>Popular</span></p>

  

 角標必須用絕對位置才能正確實現效果。

 

<article>    <img src="bacon.jpg"/>    <h2>Some title</h2>    <p><span>New!</span></p></article>

  

完整CSS代碼:

 

/** *   Flag component */.flag {    position: absolute;    top: 0;    left: 0;}/** * The traingle shape of the flag. * 1. The size of the triangle. */  .flag:before {     content: "";    position: absolute;    top: 0;    left: 0;    border-style: solid;    border-width: 34px;     /* [1] */}/* * Rotate the text and position it. * 1. Put on the GPU to ensure the text is rendered correctly */.flag-text {    -moz-transform: rotate(-45deg);    -ms-transform: rotate(-45deg);    -o-transform: rotate(-45deg);    -webkit-transform: rotate(-45deg) translateZ(0);    /* [1] */    transform: rotate(-45deg) translateZ(0);    color: #FFF;    display: inline-block;    position: absolute;    top: 18px;    left: 0;    z-index: 1;    font-size: 12px;    text-transform: uppercase;    width: 50px;    text-align: center;}/* * Modifier classes for different colour flags */.flag.is-new:before {    border-color: rgba(4,120,0,.9) transparent transparent rgba(4,120,0,.9);}.flag.is-popular:before {    border-color: rgba(206,3,5,.7) transparent transparent rgba(206,3,5,.7);}

  

註:本文為譯文。

原文連結:https://dzone.com/articles/create-a-flag-with-css

原作者demo連結:http://demo.iambacon.co.uk/css-corner-flag

使用CSS建立一個圖片角標

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.