| 1 | = Styling Form Controls Using Pseudo Classes = |
| 2 | |
| 3 | WebKit provides a way to give CSS styles to form controls. |
| 4 | Some form controls can be styled through pseudo classes. |
| 5 | This article will illustrate how we |
| 6 | can customize their appearances using the pseudo classes. |
| 7 | |
| 8 | == <progress> == |
| 9 | |
| 10 | You can customize {{{<progress>}}} element by {{{-webkit-progress-bar-value}}} pseudo class. |
| 11 | An example following: |
| 12 | |
| 13 | {{{ |
| 14 | progress.custom { |
| 15 | -webkit-appearance: none; |
| 16 | background-color: blue; |
| 17 | } |
| 18 | |
| 19 | progress.custom::-webkit-progress-bar-value { |
| 20 | background-color: red; |
| 21 | } |
| 22 | }}} |
| 23 | |
| 24 | In this example, we first disable the default visual by {{{-webkit-appearance: none}}}, |
| 25 | then give styles, one for {{{<progress>}}} element itself, another for its "bar" part. |
| 26 | |
| 27 | With this tyle, following HTML fragment... |
| 28 | |
| 29 | {{{ |
| 30 | <progress class="custom" min="0" max="100" value="30" /> |
| 31 | }}} |
| 32 | |
| 33 | ...looks like: |
| 34 | |
| 35 | XXX. |
| 36 | |
| 37 | == <meter> == |
| 38 | |
| 39 | As {{{<progress>}}}, {{{<meter>}}} can be customized by pseudo classes. |
| 40 | But it's more complicated because {{{<meter>}}} has three different 3 states ({{{optimal}}}, {{{suboptimal}}} and {{{even-less-good}}}) |
| 41 | and 2 directions ({{{horizontal}}} and {{{vertical}}}). |
| 42 | |
| 43 | WebKit defines 8 pseudo classes to handle them: |
| 44 | |
| 45 | {{{ |
| 46 | meter.custom::-webkit-meter-horizontal-bar { background: gray; } |
| 47 | meter.custom::-webkit-meter-horizontal-optimum-value { background: green; } |
| 48 | meter.custom::-webkit-meter-horizontal-suboptimal-value { background: yellow; } |
| 49 | meter.custom::-webkit-meter-horizontal-even-less-good-value { background: red; } |
| 50 | meter.custom::-webkit-meter-vertical-bar { background: gray; } |
| 51 | meter.custom::-webkit-meter-vertical-optimum-value { background: blue; } |
| 52 | meter.custom::-webkit-meter-vertical-suboptimal-value { background: purple; } |
| 53 | meter.custom::-webkit-meter-vertical-even-less-good-value { background: white; } |
| 54 | }}} |
| 55 | |
| 56 | Note that background "bar" part has directions, but has no state. |
| 57 | |
| 58 | With this style, following HTML fragment... |
| 59 | {{{ |
| 60 | <meter class="custom" style="height:20px; width:80px;" min="0" max="100" low="30" high="60" optimum="100" value="90" ></meter> |
| 61 | <meter class="custom" style="height:20px; width:80px;" min="0" max="100" low="30" high="60" optimum="100" value="30" ></meter> |
| 62 | <meter class="custom" style="height:20px; width:80px;" min="0" max="100" low="30" high="60" optimum="100" value="10" ></meter> |
| 63 | <meter class="custom" style="height:100px; width:80px;" min="0" max="100" low="30" high="60" optimum="100" value="90" ></meter> |
| 64 | <meter class="custom" style="height:100px; width:80px;" min="0" max="100" low="30" high="60" optimum="100" value="50" ></meter> |
| 65 | <meter class="custom" style="height:100px; width:80px;" min="0" max="100" low="30" high="60" optimum="100" value="10" ></meter> |
| 66 | }}} |
| 67 | |
| 68 | ...looks like this: |
| 69 | |
| 70 | XXX: |
| 71 | |
| 72 | === <meter> variations === |
| 73 | |
| 74 | On Mac OS X, WebKit provide multiple built-in appearances for {{{<meter>}}}. |
| 75 | |
| 76 | * {{{-webkit-appearance: continuous-capacity-level-indicator;}}} (Default) |
| 77 | * {{{-webkit-appearance: discrete-capacity-level-indicator;}}} |
| 78 | * {{{-webkit-appearance: relevancy-level-indicator;}}} |
| 79 | * {{{-webkit-appearance: rating-level-indicator;}}} |
| 80 | |
| 81 | You can find the rendering result in the test suite: |
| 82 | |
| 83 | * [source:trunk/LayoutTests/platform/mac/fast/dom/HTMLMeterElement/meter-appearances-capacity-expected.png] |
| 84 | * [source:trunk/LayoutTests/platform/mac/fast/dom/HTMLMeterElement/meter-appearances-rating-relevancy-expected.png] |
| 85 | |
| 86 | == <input> element == |
| 87 | |
| 88 | Coming soon... |