Select Using Styled Optgroup Tags


/ Published in: CSS
Save to your folder(s)

Having a handle for groups of options allows script driven dynamic effects to manage changes of presentation with in the select without having to refresh or use other inefficient methods of updating the display.


Copy this code and paste it in your HTML
  1. CSS:
  2.  
  3. #styled optgroup {
  4. border:1px solid red;
  5. margin:10px 8px 10px 8px;
  6. padding:10px 5px 0 5px;
  7. }
  8. #styled option {
  9. padding:2px 15px 2px 12px;
  10. }
  11. #styled optgroup option {
  12. padding-left:22px;
  13. }
  14. #optA {
  15. color:white;
  16. background-color:black;
  17. }
  18. #optA:hover {
  19. color:black;
  20. background-color:orange;
  21. }
  22. #optB {
  23. background-image:url(../images/facebook.png);
  24. background-position:top right;background-repeat:no-repeat;
  25. }
  26. #optB:hover {
  27. background-image:url(../images/dzone.png);
  28. }
  29. #optB {
  30. color:blue;
  31. }
  32. #optB option:nth-of-type(odd) {
  33. background-color:aqua;
  34. }
  35. #optB:hover option:nth-of-type(odd) {
  36. color:red;
  37. }
  38.  
  39. HTML:
  40. <select id="styled" size="15">
  41. <optgroup id="optA" label="Group A">
  42. <option value="0">zero</option>
  43. <option value="1">One</option>
  44. <option value="2">Two</option>
  45. </optgroup>
  46. <option value="3">Three</option>
  47. <optgroup id="optB" label="Group B">
  48. <option value="4">Four</option>
  49. <option value="4a">B - Four A</option>
  50. <option value="4b">B- Four B</option>
  51. <option value="4c">b - Four C</option>
  52. <option value="5">Five</option>
  53. <option value="6">Six</option>
  54. </optgroup>
  55. <option value="7">Seven</option>
  56. <option value="8">Eight</option>
  57. <option value="9">Nine</option>
  58. </select>

URL: http://coboldinosaur.com/pages/Dynamic_optgroup_Styling.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.