Skip to content

Commit f30bc4c

Browse files
authored
Style: Reduce size of code font and improve responsiveness at narrow screen widths (#2439)
1 parent 3b879dd commit f30bc4c

File tree

4 files changed

+86
-22
lines changed

4 files changed

+86
-22
lines changed

pep_sphinx_extensions/pep_theme/static/mq.css

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
@charset "UTF-8";
2+
23
/* Media Queries */
3-
@media (max-width: 32.5em) {
4-
/* Reduce padding & margins for the smallest screens */
4+
5+
/* Further reduce width of fixed elements for smallest screens */
6+
@media (max-width: 32em) {
7+
section#pep-page-section {
8+
padding: 0.25rem;
9+
}
10+
dl.footnote > dt,
11+
dl.footnote > dd {
12+
padding-left: 0;
13+
padding-right: 0;
14+
}
15+
pre {
16+
font-size: 0.75rem;
17+
}
18+
}
19+
20+
/* Reduce padding & margins for smaller screens */
21+
@media (max-width: 40em) {
22+
section#pep-page-section {
23+
padding: 0.5rem;
24+
}
525
section#pep-page-section > header > h1 {
626
padding-right: 0;
727
border-right: none;
@@ -12,22 +32,22 @@
1232
nav#pep-sidebar {
1333
display: none;
1434
}
35+
pre {
36+
font-size: 0.8175rem;
37+
}
1538
table th,
1639
table td {
1740
padding: 0 0.1rem;
1841
}
1942
}
20-
@media (min-width: 32.5em) {
43+
44+
@media (min-width: 40em) {
2145
section#pep-page-section {
22-
max-width: 40em;
23-
width: 100%;
46+
display: table;
2447
margin: 0 auto;
25-
padding: .5rem 1rem 0;
26-
}
27-
}
28-
@media (min-width: 54em) {
29-
section#pep-page-section {
3048
max-width: 75em;
49+
padding: 0.5rem 1rem 0;
50+
width: 100%;
3151
}
3252
section#pep-page-section > article {
3353
max-width: 40em;
@@ -41,6 +61,11 @@
4161
float: left;
4262
margin-right: 2%;
4363
}
64+
/* Make less prominent when sidebar ToC is available */
65+
details > summary {
66+
font-size: 1rem;
67+
width: max-content;
68+
}
4469
}
4570
@media (min-width: 60em) {
4671
section#pep-page-section > article {

pep_sphinx_extensions/pep_theme/static/style.css

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
:root {color-scheme: light dark}
2020
html {
2121
overflow-y: scroll;
22-
-webkit-font-smoothing: antialiased;
2322
margin: 0;
2423
line-height: 1.4;
2524
font-weight: normal;
@@ -32,16 +31,14 @@ body {
3231
background-color: var(--colour-background);
3332
}
3433
section#pep-page-section {
35-
padding: 0.25rem 0.25rem 0;
36-
display: table;
34+
padding: 0.25rem;
3735
}
3836

3937
/* Reduce margin sizes for body text */
4038
p {margin: .5rem 0}
4139

4240
/* Header rules */
4341
h1 {
44-
line-height: 2.3;
4542
font-size: 2rem;
4643
font-weight: bold;
4744
margin-top: 2rem;
@@ -78,8 +75,10 @@ a,
7875
a:active,
7976
a:visited {
8077
color: var(--colour-links);
81-
text-decoration-color: var(--colour-background-accent);
8278
display: inline;
79+
overflow-wrap: break-word;
80+
overflow-wrap: anywhere;
81+
text-decoration-color: var(--colour-background-accent);
8382
}
8483
a:hover,
8584
a:focus {
@@ -105,22 +104,33 @@ cite {
105104
pre,
106105
code {
107106
font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "DejaVu Sans Mono", Consolas, monospace;
107+
font-size: 0.875rem;
108108
white-space: pre-wrap;
109-
word-wrap: break-word;
110109
-webkit-hyphens: none;
111110
hyphens: none;
112111
}
112+
code {
113+
overflow-wrap: break-word;
114+
overflow-wrap: anywhere;
115+
}
113116
code.literal {
114117
font-size: .8em;
115118
background-color: var(--colour-inline-code);
116119
}
117120
pre {
118121
padding: .5rem .75rem;
122+
word-break: break-all;
119123
}
120124

121125
/* Contents rules */
122126
details > summary {
127+
cursor: pointer;
128+
font-size: 1.6rem;
123129
font-weight: bold;
130+
margin-bottom: 1em;
131+
}
132+
details > summary:hover {
133+
text-decoration: underline;
124134
}
125135

126136
/* Definition list rules */
@@ -171,6 +181,9 @@ sup {top: -0.5em}
171181
sub {bottom: -0.25em}
172182

173183
/* Table rules */
184+
div.table-wrapper {
185+
overflow-x: auto;
186+
}
174187
table {
175188
width: 100%;
176189
border-collapse: collapse;
@@ -270,16 +283,11 @@ dl.footnote dd {
270283

271284
/* Sidebar formatting */
272285
#pep-sidebar {
273-
overflow-y: scroll;
286+
overflow-y: auto;
274287
position: sticky;
275288
top: 0;
276289
height: 100vh;
277-
scrollbar-width: thin; /* CSS Standards, not *yet* widely supported */
278-
scrollbar-color: var(--colour-scrollbar) transparent;
279290
}
280-
#pep-sidebar::-webkit-scrollbar {width: 6px}
281-
#pep-sidebar::-webkit-scrollbar-track {background: transparent}
282-
#pep-sidebar::-webkit-scrollbar-thumb {background: var(--colour-scrollbar)}
283291
#pep-sidebar > h2 {
284292
font-size: 1.4rem;
285293
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Wrap the tables in PEP bodies in a div, to allow for responsive scrolling
2+
3+
"use strict";
4+
5+
const pepContentId = "pep-content";
6+
7+
8+
// Wrap passed table element in wrapper divs
9+
function wrapTable (table) {
10+
const wrapper = document.createElement("div");
11+
wrapper.classList.add("table-wrapper");
12+
table.parentNode.insertBefore(wrapper, table);
13+
wrapper.appendChild(table);
14+
}
15+
16+
17+
// Wrap all tables in the PEP content in wrapper divs
18+
function wrapPepContentTables () {
19+
const pepContent = document.getElementById(pepContentId);
20+
const bodyTables = pepContent.getElementsByTagName("table");
21+
Array.from(bodyTables).forEach(wrapTable);
22+
}
23+
24+
25+
// Wrap the tables as soon as the DOM is loaded
26+
document.addEventListener("DOMContentLoaded", () => {
27+
if (document.getElementById(pepContentId)) {
28+
wrapPepContentTables();
29+
}
30+
})

pep_sphinx_extensions/pep_theme/templates/page.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ <h2>Contents</h2>
4141
</nav>
4242
</section>
4343
<script src="{{ pathto('_static/colour_scheme.js', resource=True) }}"></script>
44+
<script src="{{ pathto('_static/wrap_tables.js', resource=True) }}"></script>
4445
</body>
4546
</html>

0 commit comments

Comments
 (0)