0

I have an ASP.NET checkboxlist with "chkboxlistnames" as the class:

<asp:CheckBoxList ID ="chkName" runat="server"  RepeatDirection="Horizontal" CssClass="chkboxlistnames" >
<asp:ListItem Text="" Value=""  ></asp:ListItem>
</asp:CheckBoxList>

I populate this checkbox by using jQuery, Ajax and JSON method. After rendering HTML shows like this:

<table id="MainContent_chkName" class="chkboxlistnames">
<tbody>
<tr>
<td>
<input id="MainContent_chkName_0" name="UserID" value="2009" type="checkbox">
<label for="MainContent_chkName_0">[email protected],Lekshmi</label>
</td>
</tr>
</tbody>
</table>

CSS:

input[type="checkbox"]:not(old) + label {
    display: inline-block;
    margin-left: -8px;
    background: url('../img/checks.png') no-repeat 197px 1px;
    line-height: 24px;
    width: 222px;
    text-align: left;
}
label {
    display: inline-block;
    max-width: 100%;
    margin-bottom: 5px;
    font-weight: 700;
}

This style is used for all checkboxes in this application, but I want a separate CSS for this checkbox using class chkboxlistnames, how to do that?

5
  • Change input[type="checkbox"]:not(old) + label { as input[class="chkboxlistnames"]:not(old) + label { Commented May 4, 2017 at 6:40
  • @DavidR Why input[class="chkboxlistnames"] and not just use input.chkboxlistnames? Commented May 4, 2017 at 6:40
  • @godfrzero For one thing, the first is more precise; it works only on inputs with one class name. Commented May 4, 2017 at 6:42
  • @MrLister Not sure if that's relevant or expected in this case though. Anyway, irrelevant since the class is on the parent. Commented May 4, 2017 at 6:44
  • @David R after rendering class=chkboxlistnames added with class of table element Commented May 4, 2017 at 6:53

2 Answers 2

2

chkboxlistnames is in the parent element, so it should be like this:

.chkboxlistnames input[type="checkbox"] {
    //Your CSS goes here
}
Sign up to request clarification or add additional context in comments.

Comments

0

First method,

.chkboxlistnames input[type="checkbox"] {
   //css here
}

Second method,

#MainContent_chkName_0{
   //css here
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.