]> git.draconx.ca Git - homepage.git/blob - content/style.scss
Implement sortable file listing tables.
[homepage.git] / content / style.scss
1 /*
2  * Nick's web site: default stylesheet
3  *
4  * Copyright © 2018-2020 Nick Bowler
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19
20 // colour definitions
21 $backgroundcolour:  #ffffff;
22 $foregroundcolour:  #000000;
23
24 $linkdefaultcolour: #0000cd;
25 $linkactivecolour:  #ff0000;
26 $linkvisitedcolour: #800080;
27
28 $ruledefaultcolour: #d3d3d3;
29 $rulestrongcolour:  #696969;
30
31 $annotationcolour:  #708090;
32
33 $tableshadecolour:  #f5f5f5;
34
35 @mixin header_size($maxwidth, $fontsize) {
36     font-size: $fontsize;
37     max-width: 1em * ($maxwidth / $fontsize);
38 }
39
40 body {
41     background-color: $backgroundcolour;
42     color: $foregroundcolour;
43     font-family: sans-serif;
44     margin: 1em;
45 }
46
47 a:link { color: $linkdefaultcolour; }
48 a:visited { color: $linkvisitedcolour; }
49 a:active { color: $linkactivecolour; }
50
51 h1 { @include header_size(60em, 2em); }
52 h2 { @include header_size(60em, 1.5em); }
53 h5 { @include header_size(60em, 1em); }
54
55 p>img { max-width: 40em; width: 100%; height: auto; }
56
57 p, dt, dd, li {
58     text-align: justify;
59     @media (max-width: 28em) { text-align: left; }
60     padding: 0;
61     margin: 0;
62 }
63
64 p, table, div, ul, ol, dl, hr {
65     max-width: 50em;
66     padding: 0;
67     margin: 0;
68 }
69
70 p, table, body>div, h5 { margin: 1em 0; }
71
72 li { margin: 0 0 0 2em; }
73 dd { margin: 0 0 0 1em; }
74
75 hr {
76     clear: both;
77     margin: 0.5em 0;
78     border: 0;
79     border-top: 1px solid $ruledefaultcolour;
80 }
81
82 kbd {
83     font-family: monospace;
84     font-size: 0.95em;
85     &:before { content: "% "; }
86 }
87
88 .permalink {
89     font-size: small;
90     color: $annotationcolour;
91
92     a:link, a:visited { color: inherit; }
93     @media not screen { visibility: hidden; }
94 }
95
96 // General table styles.
97 table {
98     border: 1px solid $ruledefaultcolour;
99     border-collapse: collapse;
100     width: 100%;
101 }
102
103 table>* { font-size: 0.9em; }
104 caption {
105     caption-side: top;
106     font-weight: bold;
107     font-size: 1em;
108     text-align: left;
109     margin: 0 0 0.5em 0;
110 }
111
112 td, th {
113     vertical-align: middle;
114     text-align: left;
115     padding: 1ex;
116     margin: 0;
117 }
118
119 thead>tr, tbody>tr { border: solid $ruledefaultcolour; }
120 th, thead>tr { border-bottom: 1px solid $rulestrongcolour; }
121 *>table, *>th { border: none; }
122 thead>tr { border-width: 1px; }
123 tbody>tr { border-width: 0 1px; }
124
125 td + td { box-shadow: -1px 0 $backgroundcolour; }
126
127 tbody>tr {
128     &:nth-of-type(even) { background-color: $tableshadecolour; }
129     &:last-child { border-bottom: solid 1px $ruledefaultcolour; }
130 }
131
132 // Specific table styles
133 table.cc {
134     &>tr>*:first-child, &>*>tr>*:first-child {
135         &+* { text-align: center; }
136         text-align: center;
137     }
138 }
139
140 $sortcols: name, date, size;
141 @each $col in $sortcols {
142     #filelist-#{$col}-sort {
143         &:checked {
144             & ~ table.filelist {
145                 /* Update table header state */
146                 th.#{$col} {
147                     label~label {
148                         display: -moz-inline-box !important;
149                         display: inline-block !important;
150                     }
151                     label { display: none; }
152                 }
153
154                 /* Show only appropriate items from the sort body (forward) */
155                 tbody+tbody>tr.#{$col} { display: table-row; }
156                 tbody+tbody>tr { display: none; }
157             }
158
159             & ~ #filelist-#{$col}-rev:checked ~ table.filelist {
160                 /* Show only appropriate items from sort body (reversed) */
161                 tbody+tbody>tr.#{$col}rev { display: table-row; }
162                 tbody+tbody>tr { display: none; }
163             }
164
165             /* Unhide associated checkbox for keyboard navigation */
166             & ~ #filelist-#{$col}-rev { display: block !important; }
167         }
168
169         &:focus ~ table.filelist th>label~label>span {
170             border: 1px dotted;
171             padding: 0;
172         }
173
174         display: block !important;
175         position: absolute;
176         z-index: -1;
177         opacity: 0;
178     }
179
180     #filelist-#{$col}-rev {
181         &:checked ~ table.filelist {
182             /* Update table header state */
183             th.#{$col} {
184                 img+img {
185                     display: -moz-inline-box !important;
186                     display: inline !important;
187                 }
188                 img { display: none; }
189             }
190         }
191
192         &:focus ~ table.filelist th>label~label>img {
193             border: 1px dotted;
194             padding: 0;
195         }
196
197         position: absolute;
198         z-index: -2;
199         opacity: 0;
200     }
201 }
202
203 /* Enable the sorted tables only when non-default option is selected */
204 #filelist-name-rev, #filelist-date-sort, #filelist-size-sort {
205     &:checked~table.filelist>tbody {
206         &+tbody { display: table-row-group !important; }
207         display: none;
208     }
209 }
210
211 table.filelist {
212     &>tr>*:first-child, &>*>tr>*:first-child {
213         &+td { min-width: 50%; }
214         width: 0;
215     }
216
217     th>label>* { padding: 1px; }
218     th>label, th>label>* {
219         white-space: nowrap;
220         vertical-align: middle;
221         display: -moz-inline-box;
222         display: inline-block;
223         cursor: pointer;
224     }
225     th img { margin-left: 0.5ex; }
226
227     tbody+tbody {
228         border-bottom: solid 1px $ruledefaultcolour;
229     }
230
231     img {
232         display: block;
233         height: 1.5em;
234         width: auto;
235     }
236 }
237
238 // Site header rules
239 #breadcrumbs>*, #sitetitle>* { font-size: 0.8em; }
240 #breadcrumbs {
241     * {
242         display: inline;
243         list-style-type: none;
244         vertical-align: top;
245         padding: 0;
246         margin: 0;
247     }
248
249     li + li:before { content: "/ "; }
250 }
251 #sitetitle * {
252     display: inline-block;
253     float: right;
254 }
255
256 // Site footer rules
257 #footer, #article-info {
258     text-align: center;
259     max-width: 44em;
260     padding: 0 3em;
261     margin: 0;
262
263     p {
264         display: inline-block;
265         font-size: 0.8em;
266         max-width: 100%;
267         margin: 0.2em 0;
268     }
269 }
270
271 #footer p { color: $annotationcolour; }
272 #article-info p { font-style: italic; }
273
274 // "unordered" lists with explicit ordering in content
275 ul.ordered > {
276     li { list-style: none; }
277     li>span:first-child, li>*:first-child>span:first-child {
278         display: inline-block;
279         text-align: right;
280         margin-left: -1.8em;
281         min-width: 1.8em;
282     }
283 }
284
285 @media (max-width: 512px) {
286     body { margin: 0.6em; }
287     ul ul { margin-left: -1.2em; }
288     dd { margin: 0; }
289 }
290
291 @media (max-width: 35em) {
292     #sitetitle * { float: none; }
293     #footer { padding: 0 1em; }
294 }