Skip to content

Commit 8e6f72a

Browse files
simonwclaude
andauthored
Fix footer layout on pages with flex/grid body (#173)
When the body element uses display:flex or display:grid (like california-clock-change.html), the footer was being positioned as a sibling flex item instead of at the bottom. This fix: - Detects flex/grid layouts on body - Wraps existing content in a div that preserves the original layout - Resets body to a vertical flex column - Footer now always appears at the bottom regardless of parent layout Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8152f0b commit 8e6f72a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

footer.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,43 @@
124124
textColor = isDark ? 'rgb(255, 255, 255)' : 'rgb(0, 0, 0)';
125125
}
126126

127+
// Check if body uses flex or grid layout that could break footer positioning
128+
const bodyStyle = window.getComputedStyle(document.body);
129+
const bodyDisplay = bodyStyle.display;
130+
const needsLayoutFix = (bodyDisplay === 'flex' || bodyDisplay === 'grid');
131+
132+
if (needsLayoutFix) {
133+
// Wrap existing body content to preserve the original layout behavior
134+
const wrapper = document.createElement('div');
135+
wrapper.style.cssText = `
136+
display: ${bodyDisplay};
137+
flex: 1 1 auto;
138+
flex-direction: ${bodyStyle.flexDirection};
139+
align-items: ${bodyStyle.alignItems};
140+
justify-content: ${bodyStyle.justifyContent};
141+
flex-wrap: ${bodyStyle.flexWrap};
142+
gap: ${bodyStyle.gap};
143+
width: 100%;
144+
min-height: inherit;
145+
`;
146+
147+
// Move all existing children (except scripts at the end) into the wrapper
148+
while (document.body.firstChild) {
149+
wrapper.appendChild(document.body.firstChild);
150+
}
151+
152+
// Reset body to a vertical flex column
153+
document.body.style.display = 'flex';
154+
document.body.style.flexDirection = 'column';
155+
document.body.style.alignItems = 'stretch';
156+
document.body.style.justifyContent = 'flex-start';
157+
158+
document.body.appendChild(wrapper);
159+
}
160+
127161
// Create the footer element
128162
const footer = document.createElement('footer');
163+
footer.style.cssText = 'flex-shrink: 0; width: 100%; box-sizing: border-box;';
129164
footer.innerHTML = `
130165
<hr style="margin: 2rem 0 1rem 0; border: none; border-top: 1px solid ${textColor};">
131166
<nav style="font-family: system-ui, -apple-system, sans-serif; font-size: 12px; text-align: center; font-style: normal; padding-bottom: 1rem;">

0 commit comments

Comments
 (0)