4

I am using this reference to create some styled checkboxes. It refers to using the + selector to get the label following the checkbox:

input[type="checkbox"]{}
input[type="checkbox"] + label {}

When the html is:

<input type="checkbox" />
<label>Label</label>

However, I am using MVC and Razor. When I use the following helpers:

@Html.CheckBox(...)
@Html.Label(...)

The following html is produced (as detailed in this SO question):

<input type="checkbox" />
<input type="hidden" />
<label></label>

An additional hidden input is produced between the checkbox and the input. This prevents the + selector in the CSS from finding the label as it is no longer the next element to the checkbox. How can I select the label in this scenario?

1 Answer 1

1

Use like this:

input[type="checkbox"] + input[type="hidden"] + label {}

Or if you want to target any element following after checkbox is then you may use the following:

input[type="checkbox"] + * + label {}
Sign up to request clarification or add additional context in comments.

1 Comment

not all labels? OP wants to select all labels there after?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.