CSS從大圖片上截取小表徵圖的操作_CSS精靈

來源:互聯網
上載者:User

標籤:style   blog   class   c   code   java   

1.編程思想在於:

         使用background-position屬性(設定背景映像的起始位置)。這個屬性設定背景原映像(由 background-image 定義)的位置,背景映像如果要重複,將從這一點開始。

2.CSS基礎介紹:

1.如何定位背景映像:body{ background-image:url(‘bgimage.gif‘);background-repeat:no-repeat;background-attachment:fixed;background-position:center;}
2.background-position可能的值
值 描述
top left center right 如果您僅規定了一個關鍵詞,那麼第二個值將是"center"。預設為 0% 0%
x% y% 第一個值是水平位置,第二個值是垂直位置;左上方是 0% 0%。右下角是 100% 100%;如果您僅規定了一個值,另一個值將是 50%。
xpos ypos 第一個值是水平位置,第二個值是垂直位置;左上方是 0 0。單位是像素 (0px 0px) 或任何其他的 CSS 單位;如果您僅規定了一個值,另一個值將是50%;可以混合使用 % 和 position 值。
3.實際案例

註:圖片名稱(tabicons.png)每個小表徵圖width:18px;height:18px從左上方座標為(-0px;-0px;);例如第一個對號的座標為(-0px;-0px;)第二個加號的表徵圖為(-20px;-0px;)中間依次加20個像素

3.1截取小圖表的CSS代碼如下:

.icon{    background: url(imges/tabicons.png) no-repeat;    width: 18px;    line-height: 18px;    display: inline-block;}.icon-set{ background-position: -380px -200px;}.icon-add{ background-position: -20px 0px;}

3.2調用該樣式:

<div class="icon icon-add">     test
</div>
<br />

聯繫我們

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