首页 > 解决方案 > 如何在 ASP.Net 中使用 CSS 设置 CheckBoxList 的样式?

问题描述

CheckBoxList在 ASP.Net 中有一个,我想更改选中的背景颜色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>

标签: cssasp.net

解决方案


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>

推荐阅读