It took me recently to implement a three-way switch. Well, this is one that, instead of two states "on / off", there is also an intermediate state. This is often used, for example, in the “select all” checkbox in order to show that not all elements are selected, but only a part. In general, I wanted to implement this, so that without scripts.
indeterminate property of the checkbox or writing a component on scripts, starting with jQuery and ending with Angular. But I somehow did not want for the sake of such a simple task to connect JS at all.label , and since there are three states, then this label show the current state.z-index depending on the currently selected item. CSS Slice: .tristate > input[type="radio"]:checked + input[type="radio"] { z-index: 10; } .tristate > input[type="radio"]:checked + i + label, .tristate > input[type="radio"]:checked + i + label + label { display: none; } .tristate-checkbox > input[type="radio"]:checked + input[type="radio"] + i { /* ... */ } 
Source: https://habr.com/ru/post/308034/
All Articles