I've updated the header implementation to properly handle heights and scroll margins:

Changed header height to be explicitly set using CSS variable --header-height instead of being determined by padding
Set responsive header heights:
Default: 100px
Mobile (480px): 80px
Small Mobile (320px): 60px
Ensured scroll-margin-top on headings uses the same --header-height variable
Main content padding-top uses the same --header-height variable
These changes ensure consistent header heights across all screen sizes and proper scroll positioning for anchor links.
This commit is contained in:
ben7sys
2024-11-17 10:24:23 +01:00
parent 956238800d
commit ac328d8b3e
4 changed files with 23 additions and 18 deletions

View File

@@ -20,6 +20,10 @@ body {
will-change: background-color, color; will-change: background-color, color;
} }
h1, h2, h3 {
scroll-margin-top: var(--header-height);
}
h1 { h1 {
font-size: 2rem; font-size: 2rem;
margin-bottom: var(--spacing-lg); margin-bottom: var(--spacing-lg);

View File

@@ -4,14 +4,13 @@ header {
width: 100%; width: 100%;
background: linear-gradient(90deg, var(--header-gradient-1), var(--header-gradient-2)); background: linear-gradient(90deg, var(--header-gradient-1), var(--header-gradient-2));
backdrop-filter: blur(10px); backdrop-filter: blur(10px);
padding: 0.5rem var(--spacing-md); height: var(--header-height);
z-index: 1000; z-index: 1000;
border-bottom: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color);
left: 0; left: 0;
right: 0; right: 0;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transition: var(--theme-transition), transform 0.7s ease, box-shadow 0.7s ease; transition: var(--theme-transition), transform 0.7s ease, box-shadow 0.7s ease;
max-height: var(--header-height);
transform: var(--gpu-accelerated); transform: var(--gpu-accelerated);
} }
@@ -22,6 +21,7 @@ header {
max-width: 1100px; max-width: 1100px;
margin: 0 auto; margin: 0 auto;
padding: 0 var(--spacing-md); padding: 0 var(--spacing-md);
height: 100%;
} }
.logo-container { .logo-container {
@@ -58,7 +58,7 @@ header {
padding: 0.5rem 0.8rem; padding: 0.5rem 0.8rem;
border-radius: var(--border-radius); border-radius: var(--border-radius);
position: relative; position: relative;
background-color: rgba(var(--bg-hover-nav), 0.4); background-color: rgba(var(--bg-hover-nav));
letter-spacing: 0.3px; letter-spacing: 0.3px;
} }

View File

@@ -5,7 +5,7 @@
} }
header { header {
padding: 1rem; height: var(--header-height);
} }
.logo-text { .logo-text {
@@ -59,11 +59,11 @@
.nav-menu { .nav-menu {
display: none; display: none;
position: fixed; position: fixed;
top: 55px; top: var(--header-height);
left: 0; left: 0;
right: 0; right: 0;
background: var(--bg-card); background: var(--bg-card);
min-height: calc(100vh - 55px); min-height: calc(100vh - var(--header-height));
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
border-bottom: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color);
@@ -98,13 +98,16 @@
/* Mobile Devices */ /* Mobile Devices */
@media (max-width: 480px) { @media (max-width: 480px) {
:root {
--header-height: 80px;
}
.container { .container {
padding: 0 1rem; padding: 0 1rem;
} }
header { header {
padding: 0.75rem; height: var(--header-height);
max-height: 120px;
} }
.logo-text { .logo-text {
@@ -157,18 +160,16 @@
padding: 1.5rem; padding: 1.5rem;
margin: 0; margin: 0;
} }
.nav-menu {
top: 50px;
min-height: calc(100vh - 50px);
}
} }
/* Small Mobile Devices */ /* Small Mobile Devices */
@media (max-width: 320px) { @media (max-width: 320px) {
:root {
--header-height: 60px;
}
header { header {
padding: 0.5rem; height: var(--header-height);
max-height: 100px;
} }
.logo-text { .logo-text {

View File

@@ -13,8 +13,8 @@
--header-gradient-1: rgba(237, 237, 237, 0.9); --header-gradient-1: rgba(237, 237, 237, 0.9);
--header-gradient-2: rgba(228, 228, 228, 0.9); --header-gradient-2: rgba(228, 228, 228, 0.9);
--border-color: rgba(58, 123, 224, 0.1); --border-color: rgba(58, 123, 224, 0.1);
--bg-hover-rgb: 228, 228, 228; --bg-hover-rgb: 237, 237, 237;
--bg-hover-nav: 241, 241, 241; --bg-hover-nav: 207, 207, 207;
} }
[data-theme="dark"] { [data-theme="dark"] {
@@ -36,7 +36,7 @@
--spacing-xl: 2rem; --spacing-xl: 2rem;
--border-radius: 8px; --border-radius: 8px;
--transition-speed: 0.3s; --transition-speed: 0.3s;
--header-height: 140px; --header-height: 100px;
/* Theme transition with GPU acceleration */ /* Theme transition with GPU acceleration */
--theme-transition: color var(--transition-speed) ease, --theme-transition: color var(--transition-speed) ease,