CSS selector for the next but one element, checkboxes and labels in MVC forms

I use this link to create some style flags. It refers to using a selector +to get the label after this checkbox:

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

When html:

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

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

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

The following has been produced html(as described in this SO question ):

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

Additional hidden input is created between the checkbox and the input. This does not allow the selector +to CSSfind label, since it is no longer the next element checkbox. How can I choose labelin this scenario?

+4
1

:

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

, , , :

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

Source: https://habr.com/ru/post/1607449/


All Articles