2014-06-13 58 views
-1

我在垂直居中檢查符號時遇到問題。默認情況下,它位於左下角。帶圖像的複選框列表

這是我的CheckBoxList什麼樣子: enter image description here

,這是我多麼希望它看起來像: enter image description here

<asp:CheckBoxList ID="FoodCheckBoxList" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"> 
     <asp:ListItem> <img src="../images/foods/Food1.png" /> </asp:ListItem> 
     <asp:ListItem> <img src="../images/foods/Food2.png" /> </asp:ListItem> 
     <asp:ListItem> <img src="../images/foods/Food3.png" /> </asp:ListItem> 
     <asp:ListItem> <img src="../images/foods/Food4.png" /> </asp:ListItem> 
     <asp:ListItem> <img src="../images/foods/Food5.png" /> </asp:ListItem> 
     <asp:ListItem> <img src="../images/foods/Food6.png" /> </asp:ListItem> 
     <asp:ListItem> <img src="../images/foods/Food7.png" /> </asp:ListItem> 
     <asp:ListItem> <img src="../images/foods/Food8.png" /> </asp:ListItem> 
     <asp:ListItem> <img src="../images/foods/Food9.png" /> </asp:ListItem> 
</asp:CheckBoxList> 
+0

請將您的代碼張貼在小提琴上。 –

+0

嘗試爲等於圖像高度的複選框設置行高並給出vertical-align:middle;如果你可以在你的代碼 –

+0

soooo中使用css。爲什麼downvote? –

回答

3

一些研究,我這個解決方案結束後:

html

<asp:CheckBoxList ID="FoodCheckBoxList" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" ClientIDMode="Static"> 
     <asp:ListItem> <img src="" style="width:128px;height:128px;background:blue" /> </asp:ListItem> 
     <asp:ListItem> <img src="" style="width:128px;height:128px;background:blue" /> </asp:ListItem> 
     <asp:ListItem> <img src="" style="width:128px;height:128px;background:blue" /> </asp:ListItem> 
     <asp:ListItem> <img src="" style="width:128px;height:128px;background:blue" /> </asp:ListItem> 
     <asp:ListItem> <img src="" style="width:128px;height:128px;background:blue" /> </asp:ListItem> 
     <asp:ListItem> <img src="" style="width:128px;height:128px;background:blue" /> </asp:ListItem> 
     <asp:ListItem> <img src="" style="width:128px;height:128px;background:blue" /> </asp:ListItem> 
     <asp:ListItem> <img src="" style="width:128px;height:128px;background:blue" /> </asp:ListItem> 
</asp:CheckBoxList> 

不要責怪我的內聯風格只是使用它而不是圖像。

CSS

#FoodCheckBoxList [type="checkbox"] { 
    margin: 0; 
    vertical-align: middle; 
    position: relative; 
    top: 70px; 
    } 

    label { 
    display: block; 
    padding-left: 35px; 
    text-indent: -20px; 
    } 

當然你也可以用像素髮揮它調整到您的需求。

enter image description here

+0

不明白你的意思。你能解釋一下嗎? –

+0

當他們搜索他們的問題時,人們尋找接受答案的問題。如果你的答案被接受,這將有助於未來的搜索者找到他們的問題的答案。我想,你可以在8小時後將你的答案標記爲接受。 – pixelmeow

+0

如果此答案解決了他的問題,則OP應將我的答案標記爲已接受。我不能這樣做;) –