How can I (CSS-only) style an input
with type="checkbox"
, and keep the existing label
declared for
that input element?
<p id="lorem-ipsum">
<label for="dolor-sit-amet">Dolor sit amet</label>
<input type="checkbox" id="dolor-sit-amet" name="dolor" />
</p>
I want to style the checkbox element so that it has a "flip switch" appearance and behaviour.
Keep the existing label
There are numerous articles (an example from 2012) that describe this kind of complete change to the appearance of a checkbox, but I haven't found one that lets the label (as already used in the above document) remain untouched.
For this reason, many of the answers in this similar StackOverflow question do not apply here.
In other words: I want to keep the label
element as already written, and I want to have the checkbox styled like a flip switch with "on" and "off" inside it.
How can I do that without changing or styling the existing label
element, and instead styling the input
element?