Changes between Version 10 and Version 11 of Styling Form Controls
- Timestamp:
- Apr 18, 2011, 1:34:29 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Styling Form Controls
v10 v11 10 10 == <progress> == 11 11 12 You can customize {{{<progress>}}} element by {{{-webkit-progress-bar-value}}} pseudo class. 13 An example following: 12 By giving "{{{-webkit-appearance: none;}}}", {{{<progress>}}} element creates two internal elements for its rendering. 13 Since each internal element has a pseudo class, you can customize the appearance by changing the style of these pseudo classes. 14 14 15 15 {{{ 16 progress.custom { 17 -webkit-appearance: none; 18 background-color: blue; 19 } 20 21 progress.custom::-webkit-progress-bar-value { 22 background-color: red; 23 } 16 <progress> 17 ┗ <div> ::-webkit-progress-bar 18 ┗ <div>::-webkit-progress-value 24 19 }}} 25 20 26 In this example, we first disable the default visual by {{{-webkit-appearance: none}}}, 27 then give styles, one for {{{<progress>}}} element itself, another for its "bar" part.21 The default appearance is defined in http://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css . 22 Note that the width value of {{{-webkit-progress-value}}} is overwritten internally by WebKit based on the {{{value}}} atribute. 28 23 29 With this tyle, following HTML fragment...24 You can find [http://trac.webkit.org/browser/trunk/LayoutTests/fast/dom/HTMLProgressElement/progress-bar-value-pseudo-element.html an example] of {{{<progress>}}} appearance customization in the WebKit test suite. 30 25 31 {{{ 32 <progress class="custom" min="0" max="100" value="30" /> 33 }}} 26 [[Image(source:trunk/LayoutTests/platform/mac/fast/dom/HTMLProgressElement/progress-bar-value-pseudo-element-expected.png, 25%)]] 34 27 35 ...looks like:36 37 [[Image(custom-progress.png, 25%)]]38 39 Of course, we can also set properties other than {{{background-color}}}.40 28 41 29 == <meter> == 42 30 43 As {{{<progress>}}}, {{{<meter>}}} can be customized by pseudo classes. 44 But it's more complicated because {{{<meter>}}} has three different 3 states ({{{optimal}}}, {{{suboptimal}}} and {{{even-less-good}}}) 45 and 2 directions ({{{horizontal}}} and {{{vertical}}}). 46 47 WebKit defines 8 pseudo classes to handle them: 48 31 As {{{<progress>}}}, {{{<meter>}}} also creates internal elements for rendering when "{{{-webkit-appearance: none;}}}" is given. 32 Internal elements hierarchy is almost same as {{{<progress>}}} 33 49 34 {{{ 50 meter.custom::-webkit-meter-horizontal-bar { background: gray; } 51 meter.custom::-webkit-meter-horizontal-optimum-value { background: green; } 52 meter.custom::-webkit-meter-horizontal-suboptimal-value { background: yellow; } 53 meter.custom::-webkit-meter-horizontal-even-less-good-value { background: red; } 54 meter.custom::-webkit-meter-vertical-bar { background: gray; } 55 meter.custom::-webkit-meter-vertical-optimum-value { background: blue; } 56 meter.custom::-webkit-meter-vertical-suboptimal-value { background: purple; } 57 meter.custom::-webkit-meter-vertical-even-less-good-value { background: white; } 35 <meter> 36 ┗ <div> ::-webkit-progress-bar 37 ┗ <div> ::-webkit-meter-optimum-value, ::-webkit-meter-suboptimum-value, ::-webkit-meter-even-less-good-value 58 38 }}} 59 39 60 Note that background "bar" part has directions, but has no state. 40 Note that the pseudo class of the second element dynamically changes based on element's {{{value}}} attribute. 41 The width value of {{{-webkit-progress-value}}} is overwritten internally as {{{<progress>}}}. 61 42 62 With this style, following HTML fragment... 63 {{{ 64 <meter class="custom" style="height:20px; width:80px;" 65 min="0" max="100" low="30" high="60" optimum="100" value="90" ></meter> 66 <meter class="custom" style="height:20px; width:80px;" 67 min="0" max="100" low="30" high="60" optimum="100" value="30" ></meter> 68 <meter class="custom" style="height:20px; width:80px;" 69 min="0" max="100" low="30" high="60" optimum="100" value="10" ></meter> 70 <meter class="custom" style="height:100px; width:80px;" 71 min="0" max="100" low="30" high="60" optimum="100" value="90" ></meter> 72 <meter class="custom" style="height:100px; width:80px;" 73 min="0" max="100" low="30" high="60" optimum="100" value="50" ></meter> 74 <meter class="custom" style="height:100px; width:80px;" 75 min="0" max="100" low="30" high="60" optimum="100" value="10" ></meter> 76 }}} 43 [http://trac.webkit.org/browser/trunk/LayoutTests/fast/dom/HTMLMeterElement/meter-styles.html An example] is also available for {{{<meter>}}} customization in the test suite. 77 44 78 ...looks like:79 45 80 [[Image(custom-meter.png, 25%)]] 46 [[Image(source:trunk/LayoutTests/platform/mac/fast/dom/HTMLMeterElement/meter-styles-expected.png, 25%)]] 47 81 48 82 49 === <meter> variations === 83 50 84 On Mac OS X, WebKit provide multiple built-in appearances for {{{<meter>}}}.51 On Mac OS X, WebKit provides multiple built-in appearances for {{{<meter>}}}. 85 52 86 53 * {{{-webkit-appearance: continuous-capacity-level-indicator;}}} (Default)