Skip to content

Commit 7575dc3

Browse files
committed
move r[rules] to the left of the main body, using a grid
1 parent 183dd4b commit 7575dc3

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

theme/reference.css

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,46 @@ dfn {
156156

157157
/* Rules are generated via r[foo.bar] syntax, processed by mdbook-spec. */
158158
.rule {
159-
/* Allows the rule to be positioned. */
160-
position: relative;
161-
/* Position slightly to the left. */
162-
left: -4em;
163-
color: #999;
164159
font-size: 0.8em;
165160
}
166-
/* mdbook will wrap the rule content in a <p> tag, with a margin. However, we
167-
don't need the extra space
168-
*/
169-
.rule ~ p {
170-
margin-top: 0px;
161+
162+
main {
163+
/* To nicely display rules (`[a.b.c]`) on a side of the main text body we
164+
use grid layout. */
165+
display: grid;
166+
grid-template-columns:
167+
/* Left margin / place for rules */
168+
[rules] minmax(20px, 1fr)
169+
/* The main text body */
170+
[text] auto
171+
/* Right margin */
172+
[margin] minmax(20px, 1fr);
173+
max-width: none !important;
171174
}
172175

173-
/* When the sidebar is visible, reduce the spacing of rules so that the
174-
content doesn't get shifted too far, and make the text too narrow.
175-
*/
176-
.sidebar-visible .rule {
177-
left: -1em;
176+
main > * {
177+
/* By default grid items can't be smaller than their content.
178+
That is, by default `min-width: auto`.
179+
We want to be able to force code blocks to be scrollable,
180+
so we need to overwrite `min-width`. */
181+
min-width: 0;
182+
max-width: var(--content-max-width);
183+
184+
/* All elements should be in the main text body... */
185+
grid-column: text;
186+
}
187+
188+
main > .rule {
189+
/* ... except the rules, which must be in the left margin */
190+
grid-column: rules;
178191
}
179-
.sidebar-visible .content main {
180-
padding-left: 1em;
192+
193+
main > .rule {
194+
max-width: unset;
195+
justify-self: right;
196+
width: 100%;
181197
}
182198

183-
/* Remove the blue coloring of links on rules that mdbook normally sets. */
184199
.rule-link {
185200
color: #999 !important;
186201
}

0 commit comments

Comments
 (0)