Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ mark {
margin: 0 auto;
min-width: 0;
max-width: 1000px;
padding: 0.8rem 20px 0 20px;
padding: 0 20px;
margin-top: 0.8rem;
transition: 0.4s;
-webkit-transition: 0.4s;
}
Expand All @@ -66,7 +67,6 @@ mark {
position: sticky;
top: 0;
flex: 0 0 auto;
padding-top: 1rem;
max-width: 300px;
width: 300px;
}
Expand Down
7 changes: 6 additions & 1 deletion docs/userGuide/tweakingThePageStructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,18 @@ Headers are commonly included inside the html `<header>` tag. In encouraging thi
****To fix the `<header>`****
1. Add the `fixed` attribute to your `<header>` element in the layout per the above example.

2. Then, to add the necessary top padding for the main content, add the `fixed-header-padding` class to **elements that should be shifted down** in accordance with the fixed header.
2. Then, to add the necessary top padding for the main content, add the `fixed-header-padding` class to **elements that should be shifted down** in accordance with the height of the fixed header.

<box type="tip" seamless>

If you are not sure where to put the `fixed-header-padding` attribute, you may also refer to the default template for `markbind init`, which already has this setup.
</box>

<box type="warning" header="When `fixed` positioning is applied" seamless>

To detect the height of the fixed header for use in the `fixed-header-padding` class, runtime style detection is required. This results in improperly formatted content on page load for a brief period. To avoid this, the implementation here switches the `<header>` element to use `fixed` positioning, and adjusts the `fixed-header-padding` class's attribute only once the user has scrolled past the top of the header.
</box>

---

### Constructing a site navigation menu easily
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/functional/test_site/stylesheets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ mark {
margin: 0 auto;
min-width: 0;
max-width: 1000px;
padding: 0.8rem 20px 0 20px;
padding: 0 20px;
margin-top: 0.8rem;
transition: 0.4s;
-webkit-transition: 0.4s;
}
Expand All @@ -66,7 +67,6 @@ mark {
position: sticky;
top: 0;
flex: 0 0 auto;
padding-top: 1rem;
max-width: 300px;
width: 300px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ mark {
margin: 0 auto;
min-width: 0;
max-width: 1000px;
padding: 0.8rem 20px 0 20px;
padding: 0 20px;
margin-top: 0.8rem;
transition: 0.4s;
-webkit-transition: 0.4s;
}
Expand All @@ -66,7 +67,6 @@ mark {
position: sticky;
top: 0;
flex: 0 0 auto;
padding-top: 1rem;
max-width: 300px;
width: 300px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ mark {
margin: 0 auto;
min-width: 0;
max-width: 1000px;
padding: 0.8rem 20px 0 20px;
padding: 0 20px;
margin-top: 0.8rem;
transition: 0.4s;
-webkit-transition: 0.4s;
}
Expand All @@ -66,7 +67,6 @@ mark {
position: sticky;
top: 0;
flex: 0 0 auto;
padding-top: 1rem;
max-width: 300px;
width: 300px;
}
Expand Down
14 changes: 14 additions & 0 deletions packages/core-web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ function detectAndApplyFixedHeaderStyles() {
}
};

/*
Handle dynamically fixed header listener to
prevent FOUC from sudden quick movement of padding-top application.
see https://www.w3schools.com/howto/howto_js_sticky_header.asp
*/
const dynamicFixedHeaderListener = () => {
if (window.scrollY > headerSelector[0].offsetTop) {
document.documentElement.style.setProperty('--header-padding', 'var(--header-height)');
document.documentElement.style.setProperty('--header-position', 'fixed');
window.removeEventListener('scroll', dynamicFixedHeaderListener);
}
};
window.addEventListener('scroll', dynamicFixedHeaderListener);

let lastOffset = 0;
let lastHash = window.location.hash;
const toggleHeaderOnScroll = () => {
Expand Down
13 changes: 11 additions & 2 deletions packages/core-web/src/styles/markbind.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
:root {
--header-height: 0;
--header-padding: 0;
--header-position: 'static';
}

a {
Expand Down Expand Up @@ -128,8 +130,9 @@ code.hljs.inline {
/* Header */

header[fixed] {
position: var(--header-position);
top: 0;
max-height: 100%;
position: fixed;
transition: max-height 0.6s ease-in;
width: 100%;
z-index: 1001;
Expand All @@ -149,8 +152,14 @@ header[fixed] .nav-menu-open {
max-height: calc(-1 * var(--header-height) + 100% + 50px);
}

/*
Prevent sudden quick movement of page content with the dynamically fixed header.
The padding-top property is set dynamically according to the header height in index.js.
(see https://www.w3schools.com/howto/howto_js_sticky_header.asp)
*/
.fixed-header-padding {
padding-top: var(--header-height) !important;
padding-top: var(--header-padding) !important;
transition: padding-top 0s linear !important;
}

/* #app is treated as the main container */
Expand Down
4 changes: 2 additions & 2 deletions packages/core/template/default/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ mark {
margin: 0 auto;
min-width: 0;
max-width: 1000px;
padding: 0.8rem 20px 0 20px;
padding: 0 20px;
margin-top: 0.8rem;
transition: 0.4s;
-webkit-transition: 0.4s;
}
Expand All @@ -66,7 +67,6 @@ mark {
position: sticky;
top: 0;
flex: 0 0 auto;
padding-top: 1rem;
max-width: 300px;
width: 300px;
}
Expand Down