]> git.cworth.org Git - lmno.games/commitdiff
Add styling for some mobile-friendly forms and form fields
authorCarl Worth <cworth@cworth.org>
Sat, 16 May 2020 20:54:52 +0000 (13:54 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 16 May 2020 22:34:12 +0000 (15:34 -0700)
These fields will reponsively decide whether to layout in 1 or 2
columns depending on whether the fields are declared as "small",
"medium", or "large" and the width of the browser's screen.

style.css

index 899b902b78e680d7ef91df985951b23cd9bc4969..65b0b17b7ac58801e9b611ce2fa9c6bcd4fd3bfb 100644 (file)
--- a/style.css
+++ b/style.css
@@ -18,3 +18,58 @@ h2 {
     font-size: 110%;
     font-weight: bold;
 }
+
+/*\
+|*|
+|*| Responsive form layout
+|*|
+\*/
+
+/*
+ *
+ * Within the form, fields can be placed in <div> elements with
+ * class "form-field". Each can also have an additional class of one
+ * of "small", "medium", or "large". These classes will be used to
+ * select either a 1- or 2-column layout for each row depending on the
+ * width of the screen.
+ *
+ * Expected layout is as follows:
+ *
+ *   "large"   rows: 1-column on all devices
+ *
+ *   "medium"  rows: 2-column on wide displays (laptop/desktop/tablet)
+ *                   1-column on small display (phones)
+ *
+ *   "small"   rows: 2-column on all devices
+ *
+ * Finally, a class of either "left" or "right" will select which
+ * column the field should appear in for fields that end up in 2
+ * columns.
+ */
+form {
+    max-width: 100%;
+    display: grid;
+    grid-template-columns: 49% 49%;
+    grid-column-gap: 2%;
+}
+
+.form-field.small.left,.form-field.medium.left {
+    grid-column-start: 1;
+}
+
+.form-field.small.right,.form-field.medium.right {
+    grid-column-start: 2;
+}
+
+.form-field.large {
+    grid-column-start: 1;
+    grid-column-end: span 2;
+}
+
+/* For a narrow screen, use a single-column for medium form fields. */
+@media screen and (max-width: 600px) {
+    .form-field.medium.left,.form-field.medium.right {
+       grid-column-start: 1;
+        grid-column-end: span 2
+    }
+}