通過使用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; }
但不幸的是,我得到以下結果
。那麼我在這裏做錯了什麼? 「繪製的CSS」是
.sprite {
background: url('sprite.png') no-repeat top left;
}
.sprite.arg16 {
background-position: 0px 0px;
width: 16px;
height: 16px;
}
和我的精靈是
啊哈!現在我明白了。但我的單元格是33x37像素是不是有解決方法? – OrElse
我不知道。我沒有你的代碼來查看是什麼導致了這個問題。您可以嘗試添加'!important' IE:'width:16px!important;''height:16px!important'不知道它是否可以在表格單元格上工作。 – Jacques