Skip to content

Commit 3fe713b

Browse files
committed
sticky navbar
1 parent 917d3f1 commit 3fe713b

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

css/style.css

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ body {
2828
font-family: "Special Elite", system-ui;
2929
background: url('../img/Fondo_liso.jpg') no-repeat center center fixed;
3030
background-size: cover;
31+
padding-top: 70px; /* This is to make sure the navbar doesn't overlap the content */
3132
}
3233

3334
/* Scrollable container */
@@ -97,10 +98,16 @@ body {
9798

9899
/*** Navigation ***/
99100
.navbar {
101+
position: fixed;
102+
top: 0;
103+
left: 0;
104+
right: 0;
105+
z-index: 999;
100106
background: var(--bs-dark) !important;
101-
width: 100%;
107+
transition: all 0.3s ease;
108+
/* width: 100%;
102109
min-height: 70px;
103-
padding: 1rem 0;
110+
padding: 1rem 0; */
104111
}
105112

106113
.navbar-brand {
@@ -113,6 +120,21 @@ body {
113120
margin-right: 10px;
114121
}
115122

123+
.navbar-nav .nav-link-active {
124+
color: var(--bs-light) !important;
125+
position: relative;
126+
}
127+
128+
.navbar-nav .nav-link-active::after {
129+
content: '';
130+
position: absolute;
131+
bottom: 0;
132+
left: 1rem;
133+
right: 1rem;
134+
height: 2px;
135+
background: var(--bs-light);
136+
}
137+
116138
.navbar-dark .navbar-nav .nav-link {
117139
color: var(--bs-white);
118140
padding: 0.5rem 1rem;
@@ -129,7 +151,7 @@ body {
129151

130152
/*** Hero Section ***/
131153
.hero-section {
132-
min-height: 90vh; /* This makes it take full viewport height */
154+
min-height: 95vh; /* This makes it take full viewport height */
133155
background: var(--bs-dark);
134156
color: var(--bs-light);
135157
padding: 0; /* Remove default padding */
@@ -667,6 +689,22 @@ body {
667689
background: var(--bs-dark);
668690
padding: 1rem;
669691
margin-top: 0.5rem;
692+
max-height: cañc(100vh - 70px);
693+
overflow-y: auto;
694+
}
695+
696+
.navbar .container-fluid .container {
697+
padding: 0 15px;
698+
}
699+
700+
.navbar-brand {
701+
z-index: 1000;
702+
position: relative;
703+
}
704+
705+
.navbar-toggler {
706+
z-index: 1000;
707+
position: relative;
670708
}
671709

672710
.section-header h2 {

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@
7171
<div class="collapse navbar-collapse" id="navbarNav">
7272
<ul class="navbar-nav">
7373
<li class="nav-item">
74-
<a href="#asHome" class="nav-link text-special active py-2"
74+
<a href="#" class="nav-link text-special active py-2"
7575
>Inicio <span class="d-none d-md-inline">/</span>
7676
<span class="english-text">Home</span></a
7777
>
7878
</li>
7979
<li class="nav-item">
80-
<a href="stratum.html" class="nav-link text-special py-2" target="_blank"
80+
<a href="#asStratum" class="nav-link text-special py-2"
8181
>Stratum</a
8282
>
8383
</li>

js/main.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,29 @@
3434
$("html, body").animate({ scrollTop: 0 }, "slow");
3535
return false;
3636
});
37+
38+
// Navbar scroll spy
39+
document.addEventListener("DOMContentLoaded", function () {
40+
var scrollSpy = new bootstrap.ScrollSpy(document.body, {
41+
target: "#navbarNav",
42+
offset: 100,
43+
});
44+
45+
document.querySelectorAll(".navbar-nav a.nav-link").forEach((link) => {
46+
if (this.hash !== "") {
47+
e.preventDefault();
48+
const hash = this.hash;
49+
50+
document.querySelector(hash).scrollIntoView({
51+
behavior: "smooth",
52+
});
53+
54+
// En móvil cerrar tras pulsar un enlace
55+
const navbarToggle = document.querySelector(".navbar-toggler");
56+
if (window.getComputedStyle(navbarToggle).display !== "none") {
57+
document.querySelector(".navbar-collapse").classList.remove("show");
58+
}
59+
}
60+
});
61+
});
3762
})(jQuery);

0 commit comments

Comments
 (0)