✍️ 이번 클론코딩은 강의를 들으면서 새로 알게 된 지식이나 복습 및 기억해 두고 싶은 부분 위주로 작성해 보았다.😀
구글이나 네이버 등에 자신의 웹 사이트/페이지를 노출할 수 있도록 정보를 최적화 하는 작업

웹페이지가 소셜 미디어(카톡, 페이스북, 슬랙 등)로 공유될 때 우선적으로 활용되는 정보
<meta property="og:type" content="website" />
<meta property="og:site_name" content="Starbucks" />
<meta property="og:title" content="Starbucks Coffee Korea" />
<meta property="og:description" content="스타벅스는 세계에서 가장 큰 다국적 커피 전문점으로, 64개국에서 총 23,187개의 매점을 운영하고 있습니다." />
<meta property="og:image" content="./images/starbucks_seo.jpg" />
<meta property="og:url" content="https://starbucks.co.kr" />
og:type: 페이지의 유형(E.g, website, video.movie)og:site_name: 속한 사이트의 이름og:title: 페이지의 이름(제목)og:description: 페이지의 간단한 설명og:image: 페이지의 대표 이미지 주소(URL)og:url: 페이지 주소(URL)<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<a href="/" class="logo">
/ 를 넣어주면 우리 페이지의 메인페이지(현재 index.html)로 이동한다는 의미로 쓰인다.<img> 태그와 같이 인라인 요소에서는 baseline이 있으므로 불필요한 하단 여백이 생기는 현상이 생길 수 있다.img { display: block; }
header .logo {
display: flex;
align-items: center;
}
header .logo {
height: 75px;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
}
absolute로 중앙배치 하는 방법
relative 속성을 추가, logo에서는 position 속성의 absolute를 주고 위치,마진 속성을 추가해서 헤더 영역 안에서 수직 가운데에 배치가 되었다. 이렇게 absolute를 활용해서 같은 결과를 낼 수 있었다.🤔❓ 어떻게 작동되는 원리일까?
margin:auto 는 브라우저가 자동으로 값을 계산해야할 때, 요소의 상단과 하단을 측정하기 위해서 요소의 높이값(height)이 얼마인지를 정확하게 알려주어야 한다. margin:auto 와 함께 width 사이즈를 알려주고, left, right의 기준점을 0으로 입력할 수 있다.<a href="javascript:void(0)">
✍️ hash# 만 사용해왔는데, /와 자바스크립트 기능을 넣어서 원하는 결과를 각각 얻을 수 있다는 것을 새롭게 알게 되었다.
header .inner .sub-menu .menu li::before {
/* 첫번째 요소 앞은 제외하기 */
content: "";
/* display: block; */
width: 1px;
height: 12px;
background-color: #e5e5e5;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
}
height, top, bottom, margin 속성을 추가한다.position 속성의 absolute 나 fixed 는 디스플레이 속성이 block으로 바뀌므로 display: block 생략이 가능하다.header .inner .sub-menu .menu li:first-child::before {
display: none;
}
header .inner .sub-menu .search input {
width: 36px;
height: 34px;
padding: 4px 10px;
border: 1px solid #ccc;
border-radius: 5px;
outline: none;
background-color: #fff;
color: #777;
font-size: 12px;
}
background-color 에서 바탕색상이 기본적으로 흰색으로 지원되지 않는 경우를 위해 직접 명시해준다.color 에서 입력시 보여지는 글자 색상을 지정할 수 있다.outline input 태그를 클릭했을때(포커스 되었을때) 테두리에 보여지는 기본 속성(파란색박스)을 none으로 지정한다.header .inner .sub-menu .search input:focus {
width: 190px;
border-color: #669900;
}
input 코드에 transition: width 0.4s; 를 추가해서 자연스러운 애니메이션 효과를 줄 수 있다.search.addEventListener("click", () => {
searchInput.focus();
});
searchInput.addEventListener("focus", () => {});
header .inner .main-menu .item:hover .item__name {
}
.item 에 호버 했을때 .item__name 이 바뀔 속성을 명시해 준다.header .inner .main-menu .item .item__contents {
position: fixed;
left: 0;
width: 100%;
}
header .inner .main-menu .item .item__contents {
position: fixed;
left: 0;
width: 100%;
display: none;
}
header .inner .main-menu .item:hover .item__contents {
display: block;
}
display: none 으로 평상시 보이지 않도록 설정한다.display:block 으로 보이도록 설정하면 된다.😀 <li class="item">
<div class="item__name">COFFEE</div>
<div class="item__contents">
<div class="contents__menu">
<div class="inner">COFFEE</div>
</div>
<div class="contents__texture">
<div class="inner">COFFEE</div>
</div>
</div>
</li>
.inner {
position: relative;
width: 1100px;
margin: 0 auto;
}
header > .inner {
height: 120px;
}
header {
/* position: relative; */
position: fixed;
top: 0px;
width: auto;
background-color: #f6f5f0;
border-bottom: 1px solid #c8c8c8;
}
❗️ 레이아웃이 좌측 상단으로 붙어서 깨지는 것을 확인 할 수 있다. 이유가 무엇일까?
position: relative; → position: fixed; 로 변경하면서 뷰포트를 기준으로 배치가 되기 때문에 헤더라는 요소의 기본값 width:auto를 통해 브라우저가 자동으로 요소의 가로너비가 최소한으로 줄어들게 된다.width:auto 대신 width: 100%; 를 사용하면 해결 할 수 있다. 
header .badges .badge {
border-radius: 10px;
overflow: hidden;
margin-bottom: 12px;
}
<img> 태그가 있고, 이미지 경로가 지정되어 있는 상태이다.header .badges .badge img 안에서 border-radius 값을 지정해야 속성이 적용되는 줄 알았는데, 위의 코드처럼 border-radius값을 주고 현재 이미지가 넘쳐있는 상태를 조정해 주는 overflow 속성을 같이 부여해주면 같은 결과를 얻을 수 있다는 것을 알았다.👍rodash 라이브러리를 스크립트로 연결한다.
_.throttle() 라는 메소드는 화면에 스크롤시 필요한 작업을 수행할때 많이 사용된다.gsap 라이브러리를 스크립트로 연결한다.
gsap.to() gasp에서 제공하는 애니메이션 처리방법 중 to()라는 메소드의 기능을 사용한다.
const badgeEl = document.querySelector("header .badges");
window.addEventListener(
"scroll",
_.throttle(() => {
console.log(window.scrollY);
if (window.scrollY > 500) {
gsap.to(badgeEl, 0.6, {
opacity: 0,
display: "none", // 문자데이터를 필요로하는 값에는 문자데이터로 입력되어야 한다.
});
//(1) badgeEl.style.display = "none";
} else {
gsap.to(badgeEl, 0.6, {
opacity: 1,
display: "block",
});
//(2) badgeEl.style.display = "block";
}
}, 300)
);
document.addEventListener("scroll", () => {
if (window.scrollY > 300) {
badgeEl.classList.add("hide");
} else {
badgeEl.classList.remove("hide");
}
});
✍️ 라이브러리를 이용하기전, 순수 js로 classList를 이용해서 요소를 보이게 하거나 감추는 코드를 작성했는데, 여전히 보이지 않아도 클릭이 되어서 display 속성값도 none으로 지정했다. 하지만 그 이후 위와같은 이유로 애니메이션이 동작하지는 않았다.
(라이브러리를 사용해서 두 가지 기능을 손쉽게 사용할 수 있다는 것을 알았다.)
header .badges.hide {
opacity: 0;
}
✍️ css에서 주의할 것은 .visible 앞에 공간을 두지 않고 붙여서 써야한다.