Skip to content

Commit 0c7e91d

Browse files
committed
Sticky article-banner
Make article-banner ("A newer version of this document is available") sticky. This requires updating the scroll-top, otherwise when clicking on a link it would be hidden behind the banner. The existing handling already accounts for the same issue, but with the height (7.1rem) of the top nav. We use a dynamic css `var(--scroll-margin-top-space)` which can be overridden in the case that we have a banner.
1 parent 9d60e7b commit 0c7e91d

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

gulp.d/tasks/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = (src, dest, preview) => () => {
4747
},
4848
]),
4949
// NOTE importFrom is for use in supplemental CSS files
50-
postcssVar({ importFrom: path.join(src, 'css', 'vars.css'), preserve: preview }),
50+
postcssVar({ importFrom: path.join(src, 'css', 'vars.css'), preserve: true }),
5151
preview ? postcssCalc : () => {},
5252
autoprefixer,
5353
preview ? () => {} : cssnano({ preset: 'default' }),

src/css/main.css

+26-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,32 @@ main {
1212
padding-bottom: 4rem;
1313
}
1414

15-
/* IMPORTANT for this to work, the element cannot be display: flex
16-
and cannot have padding top or border top */
15+
/* This pseudo-element appears to be a home-brewed scroll-padding-top,
16+
e.g. is to prevent navigation anchor links from being hidden behind the Menu bar.
17+
18+
For this to work, the element cannot be display: flex
19+
and cannot have padding top or border top.
20+
21+
By default the var(--scroll-margin-top-space) is set to 7.1em
22+
(e.g. the height of the navbar).
23+
When a banner ("A newer version of this documentation is available")
24+
is shown, this variable is dynamically replaced to account for the
25+
banner height.
26+
*/
27+
1728
main [id]::before {
1829
content: "";
1930
display: inherit;
20-
height: var(--h2-heading-top-space);
21-
margin-top: calc(-1 * var(--h2-heading-top-space));
31+
height: var(--scroll-margin-top-space);
32+
margin-top: calc(-1 * var(--scroll-margin-top-space));
2233
visibility: hidden;
2334
width: 0;
2435
}
2536

37+
main.with-banner {
38+
--scroll-margin-top-space: var(--scroll-margin-top-space-plus-banner);
39+
}
40+
2641
main table[id]::before {
2742
display: block;
2843
}
@@ -56,18 +71,23 @@ main p {
5671
/* The "You are viewing a pre-release" banner */
5772
.article-banner {
5873
align-items: center;
59-
background: transparent;
74+
background: white;
6075
border: 1px solid #1174e0;
6176
color: var(--color-brand-blue-secondary);
6277
display: flex;
6378
line-height: 1;
6479
margin: 1.25rem 0 0;
65-
/* margin: calc(-1 * var(--height-spacer)) calc(-1 * var(--width-container-gutter)) var(--height-spacer); */
6680
padding: var(--base-space);
6781
border-radius: 3px;
6882
font-family: "Open Sans", sans-serif;
6983
font-weight: var(--weight-normal);
7084
flex-wrap: wrap;
85+
/* sticky, 2px from the top menu.
86+
Add a white shadow to top to avoid flashing moire as the text scrolls past. */
87+
position: sticky;
88+
z-index: 9;
89+
top: calc(7.1rem + 2px);
90+
box-shadow: 0 -2px white;
7191
}
7292

7393
.article-banner p {

src/css/vars.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
--height-nav: calc(var(--height-min-body) + var(--height-spacer) - var(--height-footer));
8585
--height-nav-with-version: calc(100vh - var(--height-to-body) - var(--height-version-control));
8686
--nav-menu-top-space: calc(var(--height-to-body) + var(--height-version-control));
87-
--h2-heading-top-space: calc(var(--height-to-body) + 0.5rem);
87+
--scroll-margin-top-space: calc(var(--height-to-body) + 0.5rem);
88+
--scroll-margin-top-space-plus-banner: calc(var(--height-to-body) + 0.5rem + 5rem);
8889

8990
/* widths */
9091
--width-main-gutter: 2.5rem;

src/partials/main.hbs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<main class="article" data-ceiling="topbar">
1+
<main
2+
class="article {{#unless (or (ne page.attributes.hide-view-latest undefined) (eq page.componentVersion page.component.latest))}}with-banner{{/unless}}"
3+
data-ceiling="topbar">
4+
25
{{#unless (or (ne page.attributes.hide-view-latest undefined) (eq page.componentVersion page.component.latest))}}
36
{{#with page.latest}}
47
{{#if ./missing}}

0 commit comments

Comments
 (0)