인프런 커뮤니티 질문&답변
안되는 부분 html css 및 웹 공유드립니다 확인부탁드려요
작성
·
304
1
아래 html css 및 현재 표기되고 있는 화면 공유드립니다.
<html>
<head>
<title>hojun market</title>
<link href="index.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="header">
<div id="header-area">
<img src="images/icons/logo.png" />
</div>
</div>
<div id="body">
<div id="banner">
<img src="images/banners/banner1.png" />
</div>
<h1>판매되는 상품들</h1>
<div id="product-list"></div>
<div id="footer"></div>
</div>
</body>
<script>
var products = [
{
name: "농구공",
price: 10000,
seller: "조던",
imageUrl: "/images/products/basketball1.jpeg",
},
{
name: "축구공",
price: 20000,
seller: "메시",
imageUrl: "/images/products/soccerball1.jpg",
},
{
name: "키보드",
price: 30000,
seller: "그랩",
imageUrl: "/images/products/keyboard1.jpg",
},
];
let productsHTML = "";
for (var i = 0; i < products.length; i++) {
productsHTML =
productsHTML +
'<div class="product-card">' +
"<div>" +
' <img class="product-img" src="images/products/basketball1.jpeg" />' +
"</div>" +
' <div class="product-contents">' +
' <span class="product-name">농구공 1호</span>' +
' <span class="product-price">50,000원</span>' +
'<div class="product-seller">' +
'<img class="product-avator" src="images/icons/avatar.png" />' +
" <span> 그랩 </span>";
(" </div>");
("</div>");
("</div>");
}
document.querySelector("#product-list").innerHTML = productsHTML;
</script>
</html>
css
* {
margin: 0;
padding: 0;
}
#header {
height: 64px;
border-bottom: 1px solid gray;
display: flex;
justify-content: center;
}
#body {
height: 100%;
width: 1024px;
margin: 0 auto;
padding-bottom: 24px;
}
#footer {
height: 200px;
background-color: red;
}
#banner {
height: 300px;
background-color: yellow;
}
#header-area {
width: 1024px;
height: 100%;
display: flex;
align-items: center;
}
#header-area > img {
width: 128px;
height: 36px;
}
#banner > img {
width: 100%;
}
#body > h1 {
margin-top: 16px;
}
#product-list {
display: flex;
flex-wrap: wrap;
}
.product-card {
width: 180px;
height: 300px;
margin-right: 12px;
margin-bottom: 12px;
border: 1px solid black;
border-radius: 12px;
}
.product-img {
height: 210px;
width: 100%;
}
.product-contents {
display: flex;
flex-direction: column;
padding: 8px;
}
.product-name {
font-size: 14px;
}
.product-price {
font-size: 16px;
font-weight: 600;
margin-top: 4px;
}
.product-seller {
display: flex;
align-items: center;
margin-top: 12px;
}
.product-avator {
width: 24px;
}
답변 1
1
그랩
지식공유자
현재 확인해봤는데 for문 안에 productsHTML = productsHTML + 이 부분에 오류가 있는 것 같습니다. 아래 코드를 적용해보세요~! 그리고 아래 링크에서 수업자료를 다운받으면 코드를 비교해보실 수 있습니다
https://www.inflearn.com/course/%EC%98%AC%EC%9D%B8%EC%9B%90-%EA%B0%9C%EB%B0%9C%ED%81%B4%EB%9E%98%EC%8A%A4/lecture/63338?tab=curriculum
[수강생분 코드]
[개선 코드]
for (var i = 0; i < products.length; i++) {
productsHTML =
productsHTML +
'<div class="product-card">' +
"<div>" +
'<img class="product-img" src="images/products/basketball1.jpeg" />' +
"</div>" +
'<div class="product-contents">' +
'<span class="product-name">농구공 1호</span>' +
'<span class="product-price">50,000원</span>' +
'<div class="product-seller">' +
'<img class="product-avator" src="images/icons/avatar.png" />' +
"<span> 그랩 </span>" +
"</div>" +
"</div>" +
"</div>"
}




