Optimise checkboxes for Firefox mobile
[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 IE6-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-5"><label for="kss-example-5">Standard checkbox</label>
15 // </div>
16 // <div class="mw-ui-checkbox">
17 // <input type="checkbox" id="kss-example-5-2" disabled><label for="kss-example-5-2">Disabled checkbox</label>
18 // </div>
19 //
20 // Styleguide 5.
21 .mw-ui-checkbox {
22 display: inline-block;
23 vertical-align: middle;
24 }
25
26 @checkboxSize: 1.6em;
27
28 // We use the not selector to cancel out styling on IE 8 and below
29 .mw-ui-checkbox:not(#noop) {
30 // Position relatively so we can make use of absolute pseudo elements
31 position: relative;
32 line-height: @checkboxSize;
33
34 * {
35 vertical-align: middle;
36 }
37
38 input[type="checkbox"] {
39 // we hide the input element as instead we will style the label that follows
40 // we use opacity so that VoiceOver software can still identify it
41 opacity: 0;
42 // ensure the invisible checkbox takes up the required width
43 width: @checkboxSize;
44 height: @checkboxSize;
45 // This is needed for Firefox mobile (See bug 71750 to workaround default Firefox stylesheet)
46 max-width: none;
47
48 // the pseudo before element of the label after the checkbox now looks like a checkbox
49 & + label {
50 cursor: pointer;
51 margin: 0 .4em;
52
53 &::before {
54 content: '';
55 position: absolute;
56 left: 0;
57 display: inline-block;
58 border-radius: @borderRadius;
59 margin-right: 18px;
60 width: @checkboxSize;
61 height: @checkboxSize;
62 background-color: #fff;
63 border: 1px solid grey;
64 }
65 }
66
67 // when the input is checked, style the label pseudo before element that followed as a checked checkbox
68 &:checked {
69 + label {
70 &::before {
71 .background-image-svg('images/checked.svg', 'images/checked.png');
72 .background-size( @checkboxSize, @checkboxSize );
73 background-repeat: no-repeat;
74 background-position: center top;
75 }
76 }
77 }
78
79 @focusBottomBorderSize: 0.2em;
80 &:active,
81 &:focus {
82 + label {
83 &::after {
84 content: '';
85 position: absolute;
86 width: @checkboxSize;
87 height: @checkboxSize - @focusBottomBorderSize + 0.08; // offset by bottom border
88 // offset from the checkbox by 1px to account for left border
89 left: 1px;
90 border-bottom: solid @focusBottomBorderSize lightgrey;
91 }
92 }
93 }
94
95 // disabled checked boxes have a gray background
96 &:disabled + label {
97 cursor: default;
98
99 &::before {
100 background-color: lightgrey;
101 }
102 }
103 }
104 }