JSFiddle - React, Tailwind, and code Playground
by Christopher
HTML
<select size="10">
<!-- NOT NEEDED - just as reference for disabled options with label -->
<!-- <optgroup label="Optiongroup Styling"></optgroup> -->
<!-- Behaves similar to optgroup if disabled -->
<option class="depth-0" label="Root" disabled />
<!-- Examples -->
<option class="depth-1">1</option>
<option class="depth-2" value="something">1.2</option>
<option class="depth-20" value="Level 20">20</option>
<option class="depth-0" label="Next item on Root" disabled />
<option class="depth-1" label="Sub" disabled />
<option class="depth-2" value="#fff">White</option>
</select>
<select size="10" multiple>
<!-- NOT NEEDED - just as reference for disabled options with label -->
<!-- <optgroup label="Optiongroup Styling"></optgroup> -->
<!-- Behaves similar to optgroup if disabled -->
<option class="depth-0" label="Root" disabled />
<!-- Examples -->
<option class="depth-1">1</option>
<option class="depth-2" value="something">1.2</option>
<option class="depth-20" value="Level 20">20</option>
<option class="depth-0" label="Next item on Root" disabled />
<option class="depth-1" label="Sub" disabled />
<option class="depth-2" value="#fff">White</option>
</select>
SCSS
/* can easily be adjusted to support even more */
@for $i from 0 through 100 {
select[size] option.depth-#{$i},
select[multiple] option.depth-#{$i} {
padding-left: calc(0.2em + calc(0.8em * #{$i}));
}
/**
* The label on options is handled similar to <optgroup label="...">
* (tested with chrome 87 and 95)
* This styles a <option> similar to an option group
* but it requires the attribute data-deppth and disabled
*/
select[size] option.depth-#{$i}[label]:disabled,
select[multiple] option.depth-#{$i}[label]:disabled {
font-weight: bold;
color: initial;
}
}