Skip to content

Commit 11c672c

Browse files
committed
lista de productos
1 parent cd8c453 commit 11c672c

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@
161161
</div>
162162
</aside>
163163

164+
<section class="main-container">
165+
<div class="cards-container">
166+
167+
<!-- <div class="product-card">
168+
<img src="https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" alt="">
169+
<div class="product-info">
170+
<div>
171+
<p>$120,00</p>
172+
<p>Bike</p>
173+
</div>
174+
<figure>
175+
<img src="./icons/bt_add_to_cart.svg" alt="">
176+
</figure>
177+
</div>
178+
</div> -->
179+
180+
</div>
181+
</section>
182+
164183
<script src="./main.js"></script>
165184
</body>
166185
</html>

main.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const menuCarritoIcon = document.querySelector('.navbar-shopping-cart');
44
const desktopMenu = document.querySelector('.desktop-menu');
55
const mobileMenu = document.querySelector('.mobile-menu');
66
const aside = document.querySelector('.product-detail');
7+
const cardsContainer = document.querySelector('.cards-container');
78

89
menuEmail.addEventListener('click', toggleDesktopMenu);
910
menuHamIcon.addEventListener('click', toggleMobileMenu);
@@ -38,3 +39,60 @@ function toggleCarritoAside() {
3839

3940
aside.classList.toggle('inactive');
4041
}
42+
43+
const productList = [];
44+
productList.push({
45+
name: 'Bike',
46+
price: 120,
47+
image: 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
48+
});
49+
productList.push({
50+
name: 'Pantalla',
51+
price: 220,
52+
image: 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
53+
});
54+
productList.push({
55+
name: 'Compu',
56+
price: 620,
57+
image: 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
58+
});
59+
60+
function renderProducts(arr) {
61+
for (product of arr) {
62+
const productCard = document.createElement('div');
63+
productCard.classList.add('product-card');
64+
65+
// product= {name, price, image} -> product.image
66+
const productImg = document.createElement('img');
67+
productImg.setAttribute('src', product.image);
68+
69+
const productInfo = document.createElement('div');
70+
productInfo.classList.add('product-info');
71+
72+
const productInfoDiv = document.createElement('div');
73+
74+
const productPrice = document.createElement('p');
75+
productPrice.innerText = '$' + product.price;
76+
const productName = document.createElement('p');
77+
productName.innerText = product.name;
78+
79+
productInfoDiv.appendChild(productPrice);
80+
productInfoDiv.appendChild(productName);
81+
82+
const productInfoFigure = document.createElement('figure');
83+
const productImgCart = document.createElement('img');
84+
productImgCart.setAttribute('src', './icons/bt_add_to_cart.svg');
85+
86+
productInfoFigure.appendChild(productImgCart);
87+
88+
productInfo.appendChild(productInfoDiv);
89+
productInfo.appendChild(productInfoFigure);
90+
91+
productCard.appendChild(productImg);
92+
productCard.appendChild(productInfo);
93+
94+
cardsContainer.appendChild(productCard);
95+
}
96+
}
97+
98+
renderProducts(productList);

styles.css

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,49 @@ nav {
234234
}
235235

236236

237+
/* Product List */
238+
.cards-container {
239+
display: grid;
240+
grid-template-columns: repeat(auto-fill, 240px);
241+
gap: 26px;
242+
place-content: center;
243+
margin-top: 20px;
244+
}
245+
.product-card {
246+
width: 240px;
247+
}
248+
.product-card img {
249+
width: 240px;
250+
height: 240px;
251+
border-radius: 20px;
252+
object-fit: cover;
253+
}
254+
.product-info {
255+
display: flex;
256+
justify-content: space-between;
257+
align-items: center;
258+
margin-top: 12px;
259+
}
260+
.product-info figure {
261+
margin: 0;
262+
}
263+
.product-info figure img {
264+
width: 35px;
265+
height: 35px;
266+
}
267+
.product-info div p:nth-child(1) {
268+
font-weight: bold;
269+
font-size: var(--md);
270+
margin-top: 0;
271+
margin-bottom: 4px;
272+
}
273+
.product-info div p:nth-child(2) {
274+
font-size: var(--sm);
275+
margin-top: 0;
276+
margin-bottom: 0;
277+
color: var(--very-light-pink);
278+
}
279+
237280

238281
@media (max-width: 640px) {
239282
.menu {
@@ -252,6 +295,17 @@ nav {
252295
.product-detail {
253296
width: 100%;
254297
}
298+
299+
.cards-container {
300+
grid-template-columns: repeat(auto-fill, 140px);
301+
}
302+
.product-card {
303+
width: 140px;
304+
}
305+
.product-card img {
306+
width: 140px;
307+
height: 140px;
308+
}
255309
}
256310

257311
@media (min-width: 641px) {

0 commit comments

Comments
 (0)