Skip to content

Commit ce166c3

Browse files
committed
responsive buscador ok
1 parent bdaa3b5 commit ce166c3

File tree

2 files changed

+60
-36
lines changed

2 files changed

+60
-36
lines changed

src/components/Navbar.astro

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ const { posts } = Astro.props;
44
---
55

66
<nav class="nav">
7-
<a href="/astro-proyect/"><img src="/astro-proyect/images/logo_TB_horiz_negativo-01.png" alt="The_bridge" class="logo"></a>
7+
<a href="/astro-proyect/" class="logo-link">
8+
<img src="/astro-proyect/images/logo_TB_horiz_negativo-01.png" alt="The_bridge" class="logo">
9+
</a>
810

9-
<div class="search-container">
10-
<input
11-
type="text"
12-
id="search-input"
13-
placeholder="Buscar..."
14-
aria-label="Buscar"
15-
class="search-input"
16-
style="padding: 0.5rem; border-radius: 0.25rem; border: 1px solid #ccc;"
17-
/>
18-
<ul id="search-results" class="search-dropdown"></ul>
11+
<div class="top-bar">
12+
<div class="search-container">
13+
<input
14+
type="text"
15+
id="search-input"
16+
placeholder="Buscar..."
17+
aria-label="Buscar"
18+
class="search-input"
19+
style="padding: 0.5rem; border-radius: 0.25rem; border: 1px solid #ccc;"
20+
/>
21+
<ul id="search-results" class="search-dropdown"></ul>
22+
</div>
23+
<button class="hamburger" aria-label="Toggle menu">&#9776;</button>
1924
</div>
2025

2126
<ul class="navList">
@@ -24,7 +29,6 @@ const { posts } = Astro.props;
2429
<li class="navItem"><a href="/astro-proyect/frontend/">FrontEnd</a></li>
2530
</ul>
2631

27-
<button class="hamburger" aria-label="Toggle menu">&#9776;</button>
2832
</nav>
2933

3034
<script type="module">
@@ -51,7 +55,7 @@ const { posts } = Astro.props;
5155

5256
const contentPosts = data.map(post => ({
5357
title: post.title,
54-
description: post.description,
58+
description: '',
5559
url: `/astro-proyect/${post.slug}`
5660
}));
5761

@@ -68,8 +72,7 @@ const { posts } = Astro.props;
6872
}
6973

7074
const results = posts.filter(post =>
71-
post.title.toLowerCase().includes(input) ||
72-
post.description.toLowerCase().includes(input)
75+
post.title.toLowerCase().includes(input)
7376
);
7477

7578
if (results.length === 0) {
@@ -81,6 +84,7 @@ const { posts } = Astro.props;
8184
<li class="search-result-item">
8285
<a href="${post.url}">
8386
<strong>${post.title}</strong><br>
87+
<span>${post.description}</span>
8488
</a>
8589
</li>
8690
`).join('');
@@ -116,5 +120,14 @@ const { posts } = Astro.props;
116120
initSearch();
117121
})
118122
});
123+
124+
document.addEventListener("DOMContentLoaded", function () {
125+
const nav = document.querySelector(".nav");
126+
const hamburger = document.querySelector(".hamburger");
127+
128+
hamburger.addEventListener("click", function () {
129+
nav.classList.toggle("active");
130+
});
131+
});
119132
</script>
120133

src/styles/global.css

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,39 @@ h4 {
134134

135135
@media screen and (max-width: 768px) {
136136
.nav {
137+
display: flex;
137138
flex-direction: column;
139+
align-items: flex-start;
140+
padding: 1rem;
141+
}
142+
.logo-link {
143+
width: 100%;
144+
text-align: center;
145+
margin-bottom: 1rem;
146+
}
147+
.logo {
148+
max-width: 180px;
149+
}
150+
.top-bar {
151+
display: flex;
152+
justify-content: space-between;
153+
align-items: center;
154+
width: 100%;
155+
gap: 1rem;
156+
}
157+
.search-container {
158+
flex: none;
159+
width: 70%;
160+
}
161+
162+
.hamburger {
163+
display: block;
164+
background: none;
165+
border: none;
166+
font-size: 2rem;
167+
cursor: pointer;
168+
color: white;
138169
}
139-
140170
.navList {
141171
display: none;
142172
flex-direction: column;
@@ -145,35 +175,16 @@ h4 {
145175
right: 0;
146176
margin-right: 0;
147177
background-color: #232323;
148-
width: 100%;
149178
padding: 1rem;
150179
transition: max-height 0.3s ease-in-out;
151180
max-height: 0;
152181
overflow: hidden;
153182
}
154183

155-
.hamburger {
156-
display: block;
157-
background: none;
158-
border: none;
159-
font-size: 2rem;
160-
cursor: pointer;
161-
color: white;
162-
margin-right: 1rem;
163-
padding: 0;
164-
}
165-
166-
.nav.active .navList .search-container {
184+
.nav.active .navList {
167185
display: flex;
168186
max-height: 300px;
169-
max-width: max-content;
170-
padding: 1rem;
171187
}
172-
173-
.search-container {
174-
order: 2;
175-
}
176-
177188
}
178189

179190
.back-breadcrumbs {

0 commit comments

Comments
 (0)