如何使用CSS在ASP.Net中设置我的CheckBoxList的样式?

时间:2018-09-19 15:52:06

标签: css asp.net

我在ASP.Net中有一个CheckBoxList,我想更改选中的Item的背景颜色。

我该怎么办?
我想使用CSS来做到这一点。

我的.aspx页是:

<asp:CheckBoxList ID="chkdisease" runat="server" RepeatColumns="2">
  <asp:ListItem> Spontaneous bleeding</asp:ListItem>
  <asp:ListItem>chiae (superficial tiny areas of bleeding into the skin resulting in small reddish spots) , Purpura (easy or excessive bruising),  Spontaneous bleeding from </asp:ListItem>
  <asp:ListItem>Fatigue</asp:ListItem>
  <asp:ListItem>Prolonged bleeding cuts,</asp:ListItem>
  <asp:ListItem>DVT (deep vein thrombosi</asp:ListItem>
</asp:CheckBoxList>

1 个答案:

答案 0 :(得分:0)

Css代码以更改background-color

<style>
.MyClass input[type=checkbox]:checked + label 
{
background-color:red;
} 
</style>

并将该类应用于您的CheckBoxList。像下面一样

<asp:CheckBoxList ID="chkdisease" runat="server" RepeatColumns="2" CssClass="MyClass">
<asp:ListItem> Spontaneous bleeding</asp:ListItem>
<asp:ListItem>chiae (superficial tiny areas of bleeding into the skin resulting in 
 small reddish spots) , Purpura (easy or excessive bruising),  Spontaneous bleeding 
 from </asp:ListItem>
 <asp:ListItem>Fatigue</asp:ListItem>
 <asp:ListItem>Prolonged bleeding cuts,</asp:ListItem>
 <asp:ListItem>DVT (deep vein thrombosi</asp:ListItem>
 </asp:CheckBoxList>