CSS 폴더
- css/style.css
- css/reset.css
- https://cssdeck.com/blog/scripts/eric-meyer-reset-css/ 참고
- reset.css : 브라우저마다 동일한 css값 보여주기 위하여 default값들 초기화
- 추가 후 index.html 내 link 추가
<link rel="stylesheet" href="css/reset.css">
JS 폴더
- js/main.js
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTP-8">
<title>Title</title>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/style.css">
<script src=""></script>
</head>
<body>
</body>
</html>
+) 실행 : option + b
- Header
- inner
- container
- left-box, right-box
@import "reset.css";
body{
background: #fafafa;
}
#header{
width: 100%; /*공중 부양*/
position: absolute;/*맨 위로 위치*/
z-index: 999;/*absolute의 경우 최소 x축 1개, y축 1개 필요*/
left: 0;
top: 0;
background: white;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
#header .inner{/*inner 내 컨텐츠를 넣으면 안에 값이 들어옴*/
width: 975px;
height: 77px;/*높이 값은 header내의 자식들에게 줌*/
margin: 0 auto; /*가운데 정렬*/
}
<body>
<section id="container">
<header id="header">
<section class="inner">
</section>
</header>
</section>
</body>
<body>
<section id="container">
<header id="header">
<section class="inner">
<h1 class="logo">
<a href="index.html">
</a>
</h1>
</section>
</header>
</section>
</body>
body{
background: #fafafa;
}
.sprite_insta_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -53px -235px;
width: 22px;
height: 22px;
}
.sprite_write_logo {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -94px -72px;
width: 103px;
height: 29px;
}
<body>
<section id="container">
<header id="header">
<section class="inner">
<h1 class="logo">
<a href="index.html">
<div class="sprite_insta_icon"></div>
<div class="sprite_write_logo"></div>
</a>
</h1>
</section>
</header>
</section>
</body>
위쪽에 작은 점 생김 = 'a' 태그의 배경색 때문
#header .inner .logo > a{ color: transparent;/*배경색 투명하게 만듦*/ } #header .inner .logo > div{ vertical-align: middle;/*아이콘 일직선상 위치*/ }
- 가로 정렬되는 이유
- display:inline-block;
- 원래) 블록 요소 : 화면에 배치시키면 세로 배치됨
- 세로 배치를 받는 블록 요소를 가로 배치로 시킴 : float(플롯), inline-block
#header .inner .logo .sprite_insta_icon{
position: relative;/*after 위치 기준점*/
margin-right : 30px;
}
#header .inner .logo .sprite_insta_icon:after{
content: '';/*공백을 받아옴*/
width: 1px;
height: 28px;
background: #000;
position: absolute; /*부모 기준으로 위치 잡음*/
right: -15px;
top: 0;
}
<body>
<section id="container">
<header id="header">
<section class="inner">
<h1 class="logo">
<a href="index.html">
<div class="sprite_insta_icon"></div>
<div class="sprite_write_logo"></div>
</a>
</h1>
<div class="search_box">
<input type="text" placeholder="검색" id="search-field">
<div class="fake_field">
<span class="sprite_small_search_icon"></span>
<span>검색</span>
</div>
</div>
<div class="right_icons">
<div class="sprite_camera_icon"></div>
<div class="sprite_compass_icon"></div>
<div class="sprite_heart_icon_outline"></div>
<div class="sprite_user_icon_outline"></div>
</div>
</section>
</header>
</section>
</body>
#header .inner{/*inner 내 컨텐츠를 넣으면 안에 값이 들어옴*/
width: 975px;
height: 77px;/*높이 값은 header내의 자식들에게 줌*/
margin: 0 auto; /*가운데 정렬*/
display: flex;/*가로 배치*/
justify-content: space-between;/*x축 정렬:공간 자동 분배*/
align-items: center;/*y축 정렬*/
}
#header .search_box{
position: relative;
}
@import "reset.css";
body{
background: #fafafa;
}
.sprite_insta_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -53px -235px;
width: 22px;
height: 22px;
}
.sprite_write_logo {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -94px -72px;
width: 103px;
height: 29px;
}
.sprite_compass_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -130px -286px;
width: 23px;
height: 23px;
}
.sprite_user_icon_outline {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -272px -182px;
width: 22px;
height: 24px;
}
.sprite_heart_icon_outline {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -52px -261px;
width: 24px;
height: 22px;
}
.sprite_small_search_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -337px -246px;
width: 10px;
height: 10px;
}
.sprite_more_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -301px -218px;
width: 15px;
height: 3px;
}
.sprite_bubble_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -239px -202px;
width: 24px;
height: 24px;
}
.sprite_share_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -324px -52px;
width: 21px;
height: 24px;
}
.sprite_bookmark_outline {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -237px -286px;
width: 19px;
height: 24px;
}
.sprite_bookmark_outline.on {
background: url('../imgs/background01.png') no-repeat -159px -286px;
width: 19px;
height: 24px;
}
.sprite_small_heart_icon_outline {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -323px -274px;
width: 12px;
height: 11px;
}
.sprite_camera_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -271px -104px;
width: 24px;
height: 22px;
}
.sprite_insta_big_logo {
display: inline-block;
background: url('../imgs/background02.png') no-repeat -98px -150px;
width: 175px;
height: 51px;
}
.sprite_plus_icon {
display: inline-block;
background: url('../imgs/background01.png') no-repeat -187px -202px;
width: 23px;
height: 23px;
}
#header{
width: 100%; /*공중 부양*/
position: absolute;/*맨 위로 위치*/
z-index: 999;/*absolute의 경우 최소 x축 1개, y축 1개 필요*/
left: 0;
top: 0;
background: white;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
#header .inner{/*inner 내 컨텐츠를 넣으면 안에 값이 들어옴*/
width: 975px;
height: 77px;/*높이 값은 header내의 자식들에게 줌*/
margin: 0 auto; /*가운데 정렬*/
display: flex;/*가로 배치*/
justify-content: space-between;/*x축 정렬:공간 자동 분배*/
align-items: center;/*y축 정렬*/
}
#header .inner .logo > a{
color: transparent;/*배경색 투명하게 만듦*/
}
#header .inner .logo > div{
vertical-align: middle;/*아이콘 일직선상 위치*/
}
#header .inner .logo .sprite_insta_icon{
position: relative;/*after 위치 기준점*/
margin-right : 30px;
}
#header .inner .logo .sprite_insta_icon:after{
content: '';/*공백을 받아옴*/
width: 1px;
height: 28px;
background: #000;
position: absolute; /*부모 기준으로 위치 잡음*/
right: -15px;
top: -4px;
}
#header .inner .logo .sprite_insta_icon{
position: relative;/*after에게 위치 기준 전달*/
margin-right: 30px;
}
#header .inner .logo .sprite_insta_icon:after{
content: '';/*공백 받아옴*/
width: 1px;
height: 28px;
background: #000;
position: absolute;/*부모 기준*/
right: -15px;
top: 0;
}
#header .search_box{
position:relative;/*기준점 잡고 가로배치*/
}
#search-field{
width: 185px;
height: 28px;
background:#fafafa;
border: 1px solid #dbdbdb;
border-radius: 3px;
padding:3px 30px;/*위아래 양쪽*/
color:#999;
font-weight: 400;
text-align: left;/*글자 입력 시 왼쪽부터 보이도록*/
font-size: 14px;
outline:none;/*포커스 시 나타나는 파란선*/
}
#search-field::placeholder{/*콜론2개 - 속성선택자*/
font-size: 0;/*포커스가 되지 않았을 때 : 검색 글자가 보이지 않도록 함*/
}
#search-field:focus::placeholder{
font-size: 14px;/*포커스 되었을 때 : 글자 보이게 함*/
}
#header .search_box .fake_field{
position: absolute;/*검색 창 위에 글자를 보이기*/
/*가운데 배치 공식*/
left: 50%;
top: 50%;
transform:translate(-50%,-50%);
pointer-events: none;/*검색 시 포인터 인식 불가*/
}
/*물결(~) - 근처 fake_field*/
#search-field:focus ~ .fake_field > span:nth-child(1){
transform:translateX(-105px);/*돋보기 왼쪽으로 이동*/
}
#search-field:focus ~ .fake_field > span:nth-child(2){
display: none;/*포커스 시 글자 숨기기*/
}
#header .right_icons{
width: 132px;/*부모값 좌우값 고정*/
display: flex;
justify-content: space-between;/*x축 정렬-공간 자동 분배*/
}
#header .inner .logo div{
vertical-align: middle;
}
#header .inner .logo div:nth-child(2){
transform:translateY(2px);
}