styles on optgroup
11,156
Use the CSS selector select optgroup
instead.
Be aware that not every browser will respect optgroup
rules (Webkit, for example). With that in mind, you might like to try a jQuery plugin that allows complete, cross-browsing styling of form elements; such as Uniform.
Author by
clarkk
https://dynaccount.dk https://dynaccount.dk/bogfoeringsprogram/ https://dynaccount.dk/regnskabsprogram/
Updated on August 22, 2022Comments
-
clarkk almost 2 years
How can you put a style on a optgroup in a select tag?
js:
$('<select></select>').appendTo('body').append('<option value="0">test</option>') .append($('<optgroup label="group"></optgroup>') .append('<option value="1">group test</option>'));
css:
select.optgroup[label] { font-style:normal; }
-
clarkk almost 13 yearsit works.. but how can I then reduce or remove the left padding/margin of the optgroup in the select?
-
Alex almost 13 yearsWell, as I say, it won't style all browsers, but if you want to try remove the padding & margin, then use the appropriate style declarations;
select optgroup { margin: 0; padding: 0; }