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.

Share:
11,156
clarkk
Author by

clarkk

https://dynaccount.dk https://dynaccount.dk/bogfoeringsprogram/ https://dynaccount.dk/regnskabsprogram/

Updated on August 22, 2022

Comments

  • clarkk
    clarkk almost 2 years

    How can you put a style on a optgroup in a select tag?

    http://jsfiddle.net/UCNJ8/3/

    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
    clarkk almost 13 years
    it works.. but how can I then reduce or remove the left padding/margin of the optgroup in the select?
  • Alex
    Alex almost 13 years
    Well, 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; }