OutputPage: Support HTML5 elements in older browsers using html5shiv
[lhc/web/wiklou.git] / resources / src / mediawiki.ui / components / checkbox.less
1 @import 'mediawiki.mixins';
2 @import 'mediawiki.ui/variables';
3
4 // Checkbox
5 //
6 // Styling checkboxes in a way that works cross browser is a tricky problem to solve.
7 // In MediaWiki UI put a checkbox and label inside a mw-ui-checkbox div.
8 // This renders in all browsers except IE 6-8 which do not support the :checked selector;
9 // these are kept backwards-compatible using the `:not( #noop )` selector.
10 // You should give the checkbox and label matching "id" and "for" attributes, respectively.
11 //
12 // Markup:
13 // <div class="mw-ui-checkbox">
14 // <input type="checkbox" id="kss-example-3">
15 // <label for="kss-example-3">Standard checkbox</label>
16 // </div>
17 // <div class="mw-ui-checkbox">
18 // <input type="checkbox" id="kss-example-3-checked" checked>
19 // <label for="kss-example-3-checked">Standard checked checkbox</label>
20 // </div>
21 // <div class="mw-ui-checkbox">
22 // <input type="checkbox" id="kss-example-3-disabled" disabled>
23 // <label for="kss-example-3-disabled">Disabled checkbox</label>
24 // </div>
25 // <div class="mw-ui-checkbox">
26 // <input type="checkbox" id="kss-example-3-disabled-checked" disabled checked>
27 // <label for="kss-example-3-disabled-checked">Disabled checked checkbox</label>
28 // </div>
29 //
30 // Styleguide 3.
31 .mw-ui-checkbox {
32 display: inline-block;
33 vertical-align: middle;
34 }
35
36 // We use the not selector to cancel out styling on IE 8 and below
37 // We also disable this styling on JavaScript disabled devices. This fixes the issue with
38 // Opera Mini where checking/unchecking doesn't apply styling but potentially leaves other
39 // more capable browsers with unstyled checkboxes.
40 .client-js .mw-ui-checkbox:not( #noop ) {
41 // Position relatively so we can make use of absolute pseudo elements
42 position: relative;
43 display: table;
44
45 * {
46 // reset font sizes (see T74727)
47 font: inherit;
48 vertical-align: middle;
49 }
50
51 input[type='checkbox'] {
52 // we hide the input element as instead we will style the label that follows
53 // we use opacity so that VoiceOver software can still identify it
54 opacity: 0;
55 // Render *on top of* the label, so that it's still clickable (T98905)
56 z-index: 1;
57 position: relative;
58 // ensure the invisible checkbox takes up the required width
59 width: @checkboxSize;
60 height: @checkboxSize;
61 // This is needed for Firefox mobile (See T73750 to workaround default Firefox stylesheet)
62 max-width: none;
63 margin: 0 0.4em 0 0;
64 display: table-cell;
65
66 & + label {
67 display: table-cell;
68 }
69
70 // the pseudo before element of the label after the checkbox now looks like a checkbox
71 & + label:before {
72 content: '';
73 background-color: #fff;
74 .background-image-svg( 'images/checked.svg', 'images/checked.png' );
75 background-position: center center;
76 background-origin: border-box;
77 background-repeat: no-repeat;
78 .background-size( 0, 0 );
79 .box-sizing( border-box );
80 position: absolute;
81 // align the checkbox to middle of the text
82 top: 50%;
83 left: 0;
84 width: @checkboxSize;
85 height: @checkboxSize;
86 margin-top: -1em;
87 border: 1px solid @colorGray7;
88 border-radius: @borderRadius;
89 line-height: @checkboxSize;
90 cursor: pointer;
91 }
92
93 // when the input is checked, style the label pseudo before element that followed as a checked checkbox
94 &:checked + label:before {
95 .background-size( 100%, 100% );
96 }
97
98 &:active + label:before {
99 background-color: @colorGray13;
100 border-color: @colorGray13;
101 }
102
103 &:focus + label:before {
104 border-width: 2px;
105 }
106
107 &:focus:hover + label:before,
108 &:hover + label:before {
109 border-bottom-width: 3px;
110 }
111
112 // disabled checkboxes have a gray background
113 &:disabled + label:before {
114 cursor: default;
115 background-color: @colorGray14;
116 border-color: @colorGray14;
117 }
118
119 // disabled and checked checkboxes have a white circle
120 &:disabled:checked + label:before {
121 .background-image-svg( 'images/checked_disabled.svg', 'images/checked_disabled.png' );
122 }
123 }
124 }