Skip to content

Commit 439aedb

Browse files
authored
Merge pull request #648 from alphagov/form-styling-tweaks
Update form elements to match latest designs
2 parents 26ff573 + 089d499 commit 439aedb

33 files changed

Lines changed: 624 additions & 362 deletions

File tree

app/assets/stylesheets/govuk_elements/_forms.scss

Lines changed: 146 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,82 @@
11
// Forms
22
// ==========================================================================
3-
// GOV.UK front end toolkit dependencies
4-
@import "helpers";
5-
@import "../govuk_frontend_toolkit/colours";
3+
4+
// Contents:
5+
//
6+
// 1. Helpers
7+
// 2. Form wrappers
8+
// 3. Form labels
9+
// 4. Form hints
10+
// 5. Form controls
11+
// 6. Form control widths
12+
// 7. Browser accessibility fixes
13+
14+
// 1. Helpers
15+
// ==========================================================================
616

717
// Fieldset is used to group more than one .form-group
818
fieldset {
919
@extend %contain-floats;
1020
width: 100%;
21+
22+
// Avoid extra vertical space (caused by fieldsets preventing margin collapse) when fieldsets with an h1 in the legend appear after the error-summary element.
23+
// (Class used instead of adjacent sibling selector for IE 8 compatibility.)
24+
&.after-error-summary {
25+
margin-top: -$gutter-half;
26+
27+
@include media(tablet) {
28+
margin-top: -$gutter;
29+
}
30+
}
1131
}
1232

13-
// Form group is used to wrap label and input pairs
33+
// Hack to let legends or elements within legends have margins in webkit browsers
34+
legend {
35+
overflow: hidden;
36+
}
37+
38+
// Fix left hand gap in IE7 and below
39+
@include ie-lte(7) {
40+
legend {
41+
margin-left: -7px;
42+
}
43+
}
44+
45+
// Remove margin under textarea in Chrome and FF
46+
textarea {
47+
display: block;
48+
}
49+
50+
51+
// 2. Form wrappers
52+
// ==========================================================================
53+
54+
.form-section,
1455
.form-group {
1556
@extend %contain-floats;
1657
float: left;
1758
width: 100%;
59+
}
60+
61+
// Form section is used to wrap .form-group and has twice its margin
62+
.form-section {
63+
margin-bottom: $gutter;
64+
65+
@include media(tablet) {
66+
margin-bottom: $gutter * 2;
67+
}
68+
}
69+
70+
// Form group is used to wrap label and input pairs
71+
.form-group {
1872
margin-bottom: $gutter-half;
1973

2074
@include media(tablet) {
2175
margin-bottom: $gutter;
2276
}
2377
}
2478

79+
// Form group related is used to reduce the space between label and input pairs
2580
.form-group-related {
2681
margin-bottom: 10px;
2782

@@ -30,66 +85,68 @@ fieldset {
3085
}
3186
}
3287

88+
// Form group compound is used to reduce the space between label and input pairs
3389
.form-group-compound {
3490
margin-bottom: 10px;
3591
}
3692

3793

38-
// Form title
39-
.form-title {
40-
margin-bottom: $gutter;
41-
42-
@include media(tablet) {
43-
margin-bottom: ($gutter*1.5);
44-
}
45-
}
46-
47-
48-
// Labels
94+
// 3. Form labels
95+
// ==========================================================================
4996

5097
// Form labels, or for legends styled to look like labels
98+
// TODO: Amend so there is only one label style
5199
.form-label,
52100
.form-label-bold {
53101
display: block;
54102
color: $text-colour;
103+
padding-bottom: 2px;
55104
}
56105

57106
.form-label {
58107
@include core-19;
59-
margin-bottom: 5px;
60108
}
61109

62110
.form-label-bold {
63-
@include bold-24;
64-
margin-bottom: 0;
65-
66-
.form-hint {
67-
@include core-19;
68-
}
111+
@include bold-19;
69112
}
70113

71-
// Used for paragraphs in-between form elements
114+
// Used for the 'or' in between block label options
72115
.form-block {
73-
@extend %contain-floats;
74116
float: left;
75-
width: 100%;
76-
}
117+
clear: left;
118+
119+
margin-top: -5px;
120+
margin-bottom: 5px;
77121

122+
@include media(tablet) {
123+
margin-top: 0;
124+
margin-bottom: 10px;
125+
}
126+
}
78127

79-
// Hints
128+
// 4. Form hints
129+
// ==========================================================================
80130

81-
// Form hints & examples are light grey and sit above a form control
131+
// Form hints and example text are light grey and sit above a form control
82132
.form-hint {
133+
@include core-19;
83134
display: block;
84135
color: $secondary-text-colour;
85-
margin-bottom: 5px;
136+
font-weight: normal;
86137

87-
@include media (tablet) {
88-
margin-top: 8px;
89-
}
138+
margin-top: -2px;
139+
padding-bottom: 2px;
140+
}
141+
142+
.form-label .form-hint,
143+
.form-label-bold .form-hint {
144+
margin-top: 0;
145+
padding-bottom: 0;
90146
}
91147

92-
// Form controls
148+
// 5. Form controls
149+
// ==========================================================================
93150

94151
// By default, form controls are 50% width for desktop,
95152
// and 100% width for mobile
@@ -98,21 +155,42 @@ fieldset {
98155
@include core-19;
99156
width: 100%;
100157

101-
padding: 4px;
102-
background-color: $white;
103-
border: 1px solid $border-colour;
104-
105-
// Disable webkit appearance and remove rounded corners
106-
-webkit-appearance: none;
107-
border-radius: 0;
158+
padding: 5px 4px 4px;
159+
// setting any background-color makes text invisible when changing colours to dark backgrounds in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1335476)
160+
// as background-color and color need to always be set together, color should not be set either
161+
border: 2px solid $text-colour;
108162

163+
// TODO: Remove 50% width set for tablet and up
164+
// !! BREAKING CHANGE !!
109165
@include media(tablet) {
110166
width: 50%;
111167
}
168+
112169
}
113170

171+
// Allow a qualifying element, remove rounded corners from inputs and textareas
172+
// scss-lint:disable QualifyingElement
173+
input.form-control,
174+
textarea.form-control {
175+
// Disable inner shadow and remove rounded corners
176+
-webkit-appearance: none;
177+
border-radius: 0;
178+
}
179+
180+
textarea.form-control {
181+
// Disable opacity and background image for Firefox
182+
opacity: 1;
183+
background-image: none;
184+
}
185+
// scss-lint:enable QualifyingElement
186+
114187

188+
// 6. Form control widths
189+
// ==========================================================================
190+
191+
// TODO: Update these
115192
// Form control widths
193+
116194
.form-control-3-4 {
117195
width: 100%;
118196

@@ -121,6 +199,14 @@ fieldset {
121199
}
122200
}
123201

202+
.form-control-2-3 {
203+
width: 100%;
204+
205+
@include media(tablet) {
206+
width: 66.66%;
207+
}
208+
}
209+
124210
.form-control-1-2 {
125211
width: 100%;
126212

@@ -129,44 +215,38 @@ fieldset {
129215
}
130216
}
131217

132-
.form-control-1-4 {
133-
width: 25%;
134-
}
218+
.form-control-1-3 {
219+
width: 100%;
135220

136-
.form-control-1-8 {
137-
width: 12.5%;
221+
@include media(tablet) {
222+
width: 33.33%;
223+
}
138224
}
139225

226+
.form-control-1-4 {
227+
width: 100%;
140228

141-
// Radio buttons
142-
.form-radio {
143-
display: block;
144-
margin: 10px 0;
145-
146-
input {
147-
vertical-align: middle;
148-
margin: -4px 5px 0 0;
229+
@include media(tablet) {
230+
width: 25%;
149231
}
150232
}
151233

234+
.form-control-1-8 {
235+
width: 100%;
152236

153-
// Checkboxes
154-
.form-checkbox {
155-
display: block;
156-
margin: $gutter-half 0;
157-
158-
input {
159-
vertical-align: middle;
160-
margin: -2px 5px 0 0;
237+
@include media(tablet) {
238+
width: 12.5%;
161239
}
162240
}
163241

242+
// 7. Browser accessibility fixes
243+
// ==========================================================================
164244

165-
// Buttons
166-
.form .button {
167-
@include media(mobile) {
168-
width: 100%;
169-
}
245+
option:active,
246+
option:checked,
247+
select:focus::-ms-value {
248+
color: $white;
249+
background-color: $govuk-blue;
170250
}
171251

172252

0 commit comments

Comments
 (0)