18. Position(레이어, relative, absolute, fixed)
html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="format-detection" content="telephone=no" />
<meta
name="description"
content="네이버 메인에서 다양한 정보와 유용한 컨텐츠를 만나 보세요"
/>
<title>position(레이어)</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,300,0,0"
/>
<meta property="og:type" content="website" />
<meta property="og:url" content="http://test123123.dothome.co.kr" />
<meta property="og:title" content="네이버" />
<meta
property="og:description"
content="네이버 메인에서 다양한 정보와 유용한 컨텐츠를 만나 보세요"
/>
<meta
property="og:image"
content="http://test123123.dothome.co.kr/images/20230315195155CAKTKJ.jpeg"
/>
<link rel="stylesheet" href="./css/common.css" />
<link rel="stylesheet" href="./css/main.css" />
</head>
<body>
<div id="skip_navi">
<a href="#container">본문 바로가기</a>
</div>
<div id="wrap">
<header id="header">
<div class="inner">
<h1 class="logo">
<a href="index.html">
<img src="./assets/images/logo_w.png" alt="subway" />
</a>
</h1>
<p>
pararararararpararararararpararararararpararararararpararararararpa
</p>
</div>
</header>
<main id="container">
<section class="main_etc">
<div class="inner">
<p>
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
</p>
<div class="cover">layer</div>
</div>
</section>
<section class="main_test">
<p>
amdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmkamdlkasmdlkmlkmslkdmlkasmdlkmaskldalksdmlkasmdlkmasdlkmsakldmkmklmadklmk
</p>
</section>
</main>
</div>
</body>
</html>
css
:root {
--point-color1: #03c75a;
--point-color2: #9858f5;
--txt-color-400: #404040;
--txt-color-500: #101010;
--txt-color-600: #080808;
}
#wrap {
min-width: 1280px;
height: 1500px;
}
#header {
background: #ddd;
position: fixed;
left: 0;
top: 0;
width: 100%;
z-index: 9999;
min-width: 1280px;
}
#header .inner {
width: 1200px;
height: 150px;
border: 1px solid red;
margin: 0 auto;
position: relative;
z-index: 0;
}
#header .logo {
border: 3px solid red;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: -1;
}
#header .logo img {
max-width: none;
}
#header .inner::after {
content: '';
position: absolute;
left: 30px;
right: 30px;
top: 30px;
bottom: 30px;
border: 3px solid black;
}
#header p {
font-size: 30px;
background: greenyellow;
position: absolute;
left: 0;
top: 50%;
}
#container {
padding-top: 150px;
}
.main_etc .inner {
position: relative;
width: 1200px;
height: 500px;
border: 1px solid red;
margin: 0 auto;
}
.main_etc .inner p {
font-size: 24px;
}
.main_etc .inner .cover {
position: absolute;
left: 0;
top: 0;
width: 300px;
height: 300px;
background: yellowgreen;
}
.main_test {
border: 10px solid red;
}
.main_test p {
font-size: 30px;
}
18-1. Position(레이어, Sticky)
html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="format-detection" content="telephone=no" />
<meta
name="description"
content="네이버 메인에서 다양한 정보와 유용한 컨텐츠를 만나 보세요"
/>
<title>유진그룹</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100..900&display=swap"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,300,0,0"
/>
<meta property="og:type" content="website" />
<meta property="og:url" content="http://test123123.dothome.co.kr" />
<meta property="og:title" content="네이버" />
<meta
property="og:description"
content="네이버 메인에서 다양한 정보와 유용한 컨텐츠를 만나 보세요"
/>
<meta
property="og:image"
content="http://test123123.dothome.co.kr/images/20230315195155CAKTKJ.jpeg"
/>
<link rel="stylesheet" href="./css/common.css" />
<link rel="stylesheet" href="./css/main.css" />
<link rel="stylesheet" href="./css/sub.css" />
</head>
<body>
<div id="skip_navi">
<a href="#container">본문 바로가기</a>
</div>
<div id="wrap">
<main id="container" class="network">
<div class="sub_visual">
<h2>Business network</h2>
</div>
<div class="lnb_wrap">
<ul class="lnb">
<li>
<a href="#">History</a>
</li>
<li>
<a href="#">Vision </a>
</li>
<li>
<a href="#">PR</a>
</li>
<li>
<a href="#">IR</a>
</li>
<li class="active">
<a href="#">Network</a>
</li>
</ul>
</div>
<div class="contents">
<div class="inner">
<div class="sub_tit">
<h3>건자재 유통</h3>
<p>평범한 일상을 새롭게! 유진의 다양한 이야기를 만나보세요.</p>
</div>
<ul class="sub_tab">
<li class="active">
<a href="#">유진기업(주)</a>
</li>
<li>
<a href="#">(주)동양</a>
</li>
<li>
<a href="#">(주)유진홈센터</a>
</li>
<li>
<a href="#">유진한일합섬(주)</a>
</li>
<li>
<a href="#">(주)유진디랩</a>
</li>
</ul>
</div>
</div>
</main>
</div>
</body>
</html>
css
:root {
--point-color1: #0042bf;
--point-color2: #9858f5;
--txt-color-400: #ccc;
--txt-color-500: #111;
--txt-color-600: #000;
}
#container {
}
.sub_visual {
height: 550px;
background: url(../assets/images/visual02.jpg) no-repeat 50% 0 / cover;
display: flex;
justify-content: center;
align-items: center;
padding-top: 100px;
}
.sub_visual h2 {
font-size: 70px;
color: #fff;
font-weight: 700;
padding: 0px 40px;
}
.lnb_wrap {
border-bottom: 1px solid #ddd;
background: #fefefe;
}
.lnb {
display: flex;
max-width: 1200px;
margin: 0 auto;
justify-content: center;
gap: 0 50px;
position: relative;
}
.lnb li {
}
.lnb a {
display: block;
line-height: 79px;
font-weight: 500;
padding: 0 30px;
}
.lnb li.active a {
color: var(--point-color1);
position: relative;
}
.lnb li.active a::after {
content: '';
position: absolute;
width: 100px;
height: 2px;
bottom: 0;
left: 0;
background: var(--point-color1);
}
.network {
overflow: hidden;
}
.contents {
background: #fefefe;
padding: 120px 0 200px;
}
.contents .inner {
max-width: 1200px;
padding: 0 40px;
margin: 0 auto;
}
.sub_tit {
text-align: center;
margin-bottom: 80px;
}
.sub_tit h3 {
font-size: 46px;
content: var(--txt-color-600);
font-weight: 700;
}
.sub_tit p {
color: var(--txt-color-600);
margin-top: 30px;
}
.sub_tab {
display: flex;
}
.sub_tab li {
width: 100%;
border: 1px solid #ddd;
border-right: none;
}
.sub_tab li.active {
background: var(--point-color1);
box-shadow: 3px 3px 20px rgba(154, 185, 243, 0.62);
}
.sub_tab li.active a {
color: #fff;
}
.sub_tab li:last-child {
border-right: 1px solid #ddd;
font-weight: 500;
}
.sub_tab a {
display: block;
line-height: 80px;
text-align: center;
font-size: 20px;
}
.social .sns_wrap {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-top: 126px;
}
.social .sns_wrap .sns_menu {
position: sticky;
top: 126px;
border: 5px solid black;
}
.social .sns_wrap li {
margin-bottom: 50px;
}
.social .sns_menu a {
font-size: 30px;
color: #ccc;
font-weight: 700;
}
.social .sns {
width: 65%;
display: flex;
flex-wrap: wrap;
}
.social .sns li {
width: 46%;
padding: 150px 0;
}
.social .sns li:nth-child(odd) {
margin-right: 8%;
}
.social .sns li:nth-child(even) {
margin-top: 80px;
}
.social .sns_wrap .sns {
border: 5px solid red;
width: 65%;
}
.network .sub_visual {
background-image: url(../assets/images/visual07.jpg);
}
@media (max-width: 780px) {
.lnb_wrap {
overflow: auto;
display: flex;
}
.lnb {
gap: 0;
justify-content: flex-start;
}
.lnb a {
padding: 0 16px;
font-size: 16px;
}
}
@media (max-width: 767px) {
.sub_visual {
height: 270px;
padding-top: 80px;
}
.sub_visual h2 {
font-size: 32px;
text-align: center;
}
.contents {
padding: 60px 0;
}
.contents .inner {
padding: 0 18px;
}
.sub_tit {
margin-bottom: 40px;
}
.sub_tit h3 {
font-size: 24px;
}
.sub_tit p {
font-size: 16px;
margin-top: 20px;
}
.sub_tab a {
font-size: 15px;
line-height: normal;
word-break: break-all;
height: 60px;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
}
.social .sns_menu {
flex-wrap: wrap;
}
.social .sns_menu {
position: static;
}
.social .sns {
width: 100%;
}
.social .sns li {
padding: 50px 0;
}
}
배운점
1. position-sticky가 적용 안되는 경우
- position-sticky요소 바깥 쪽에 overflow를 사용하면 sticky가 적용이 안된다!!
- flex 아이템인 경우 align-items: flex-start;로 높이가 줄어야한다!!
2. 단위가 없는 css
- z-index: 9999
- line-height: 1.5
- font-weight: 700
- 숫자 0일 경우