2013-02-07 170 views
1

這張圖片用於製作3個方向的動畫。 我只需要顯示此圖像的第一個字符。那麼我使用的背景位置 -背景位置

background-position:0px 200px; 

但它顯示完整的圖像在這裏。

樣式

position:absolute; 
    top: 40px;left: 40px; 
background-position: 0px 200px; 

圖像 - Image i want to use for first character

請引導我至JS小提琴。 Fiddle

回答

1

看到此鏈接我希望這將幫助你:http://jsfiddle.net/9RYph/7/

div { 

    top: 40px;left: 40px; 
    background-size:100%; 
    background:url('http://i.stack.imgur.com/PuAjg.jpg'); 
    width: 50%; 
    height: 600px; 
} 
1

您正在使用imgbackground-position財產img元素不會應用,你需要使用background-image財產在你的CSS,並需要在這裏設置元素的寬度,所以字符寬度是圍繞100px和高度說的200px,不是設置heightwidth200px100px分別

<div></div> 

div { 
    height: 200px; 
    width: 100px; 
    background-image: url(); 
    background-position: ; 
    background-repeat: no-repeat; 
    /* Other styles goes here */ 
} 
+0

工作確實。 – Manoj

1

你必須把這個形象一個div作爲背景,然後用background-position prope RTY。

background-position只適用於使用背景圖片。

LIVE DEMO

+0

謝謝,我得到了我想要的。 – Manoj

+0

不用@Manoj –

0

您需要設置背景圖片在#character ID:

background: url(http://img391.imageshack.us/img391/432/scorpionortholp0.jpg) 

然後添加widthheight性能,以滿足您的需求。

2

試試這個

img{ 
clip:rect(0px,300px,auto,0px); 
position:absolute; 
}