2013-11-22 31 views
2

通過使用Instand sprite我創建了我自己的精靈圖像。如何將圖像精靈集成到表格數據中?

通過使用一箇中繼器控制我的<td>類等於設置爲arg16

Private Sub cdcatalog_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles cdcatalog.ItemDataBound 
    If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then 
     Dim Cell as HtmlTableCell = TryCast(e.Item.FindControl("img"), HtmlTableCell) 
     Cell.Attributes.Add("class", "text-center sprite arg16") 
    End If 
End Sub 

在表格單元格<td id="img" runat="server" class=""></td>

.sprite { background: url('sprite.png') no-repeat top left; } 
.sprite.arg16 { background-position: 0px 0px; width: 16px; height: 16px; } 
.sprite.aus16 { background-position: 0px -26px; width: 16px; height: 16px; } 
.sprite.bel16 { background-position: 0px -52px; width: 16px; height: 16px; } 
.sprite.bra16 { background-position: 0px -78px; width: 16px; height: 16px; } 
.sprite.chl16 { background-position: 0px -104px; width: 16px; height: 11px; } 
.sprite.cyp16 { background-position: 0px -125px; width: 16px; height: 16px; } 
.sprite.den16 { background-position: 0px -151px; width: 16px; height: 16px; } 

但不幸的是,我得到以下結果

enter image description here

每個表格單元格爲

。那麼我在這裏做錯了什麼? 「繪製的CSS」是

.sprite { 
    background: url('sprite.png') no-repeat top left; 
    } 

    .sprite.arg16 { 
    background-position: 0px 0px; 
    width: 16px; 
    height: 16px; 
    } 

和我的精靈是

enter image description here

回答

1

你的表格單元格比圖像的大小。嘗試確保單元格尺寸合適。我看不到所有的代碼,但我會在下面發佈一些代碼/小提琴。

這裏是它的一個工作:http://jsfiddle.net/AU7PQ/1/

這裏是它的一個的jsfiddle不工作:http://jsfiddle.net/AU7PQ/

不同的是表格單元格中的內容在第一小提琴迫使細胞比css中指定的大。

這將與CSS工作,你必須

<table> 
    <tr> 
     <td class="sprite arg16"> 
     </td> 
    </tr> 
</table> 

這不會:

<table> 
    <tr> 
     <td class="sprite arg16"> 
      . <br /> 
      . 
     </td> 
    </tr> 
</table> 

所以,檢查,以確保您的細胞不被強迫被裏面的內容大。

+0

啊哈!現在我明白了。但我的單元格是33x37像素是不是有解決方法? – OrElse

+0

我不知道。我沒有你的代碼來查看是什麼導致了這個問題。您可以嘗試添加'!important' IE:'width:16px!important;''height:16px!important'不知道它是否可以在表格單元格上工作。 – Jacques