프론트엔드/CSS

flex 없이 탭 네비게이션 만들기

syleemomo 2021. 11. 4. 20:32
728x90

 

* 기본 구조 만들기

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="style.css" />
    <title>Flexbox</title>
  </head>
  <body>
    <div id="entire">
      <div id="contents">
        컨텐츠
      </div>
      <div id="container">
        <div class="item">아이템 1</div>
        <div class="item">아이템 2</div>
        <div class="item">아이템 3</div>
      </div>
    </div>
  </body>
</html>
body {
  padding: 0;
  margin: 0;
}
#entire {
  width: 100%;
  height: 100vh;
}
#contents {
  background: tan;
  height: 120vh;
  text-align: center;
  line-height: 200vh;
  font-size: 2rem;
}
#container {
  width: 100%;
  height: 70px;
  background: tomato;
  text-align: center;
  position: fixed;
  bottom: 0;
  z-index: 1;
  font-size: 0; /* inline-block의 기본 마진값 제거*/
}
.item {
  width: 33.2%;
  height: 100%;
  line-height: 70px;
  background: skyblue;
  display: inline-block;
  font-size: 1rem; /* 부모의 font-size 때문에 설정함 */
}
.item:nth-child(2) {
  margin-left: 0.2%;
  margin-right: 0.2%;
}
@media screen and (width: 375px), (width: 360px) {
  .item {
    width: 33%;
    height: 100%;
    line-height: 70px;
    background: skyblue;
    display: inline-block;
    font-size: 1rem; /* 부모의 font-size 때문에 설정함 */
  }
  .item:nth-child(2) {
    margin-left: 0.5%;
    margin-right: 0.5%;
  }
}

컨테이너 너비가 100%이고 마진이 0.4%일때 남는 공간은 99.6%가 되고 아이템의 너비는 3등분하면 33.2%가 된다. 

inline-block 의 기본 마진을 제거하려면 컨테이너의 font-size를 0으로 설정하면 된다. 

 

탭 네비게이션 만들기

 

* 응용하기

아이콘 찾기

 

Symbol

What is it? These special symbols are real text and available to copy and paste to anywhere, such like Microsoft Word, Facebook, Twitter, HTML or Blogging. Click icon to copy to clipboard Recently Used This will automatically collect your most recent and f

www.piliapp.com

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="style.css" />
    <title>Flexbox</title>
  </head>
  <body>
    <div id="entire">
      <div id="contents">
        컨텐츠
      </div>
      <div id="container">
        <div class="item">Home</div>
        <div class="item">About</div>
        <div class="item">Setting</div>
      </div>
    </div>
  </body>
</html>
body {
  padding: 0;
  margin: 0;
}
#entire {
  width: 100%;
  height: 100vh;
}
#contents {
  background: tan;
  height: 120vh;
  text-align: center;
  line-height: 200vh;
  font-size: 2rem;
}
#container {
  width: 100%;
  height: 70px;
  background: tomato;
  text-align: center;
  position: fixed;
  bottom: 0;
  z-index: 1;
  font-size: 0; /* inline-block의 기본 마진값 제거*/
}
.item {
  width: 33.2%;
  height: 100%;
  line-height: 70px;
  background: skyblue;
  display: inline-block;
  font-size: 1.5rem; /* 부모의 font-size 때문에 설정함 */
}
.item:nth-child(1)::before {
  content: "☃";
  padding-right: 5px;
}
.item:nth-child(2)::before {
  content: "☎";
  padding-right: 5px;
}
.item:nth-child(3)::before {
  content: "❆";
  padding-right: 5px;
}
.item:nth-child(2) {
  margin-left: 0.2%;
  margin-right: 0.2%;
}
@media screen and (width: 375px), (width: 360px) {
  .item {
    width: 33%;
    height: 100%;
    line-height: 70px;
    background: skyblue;
    display: inline-block;
    font-size: 1rem; /* 부모의 font-size 때문에 설정함 */
  }
  .item:nth-child(2) {
    margin-left: 0.5%;
    margin-right: 0.5%;
  }
}
/* 네비게이션 아이콘만 나타나게 함 */
@media screen and (width: 320px), (width: 280px) {
  .item {
    font-size: 0px;
  }
  .item:nth-child(1)::before {
    font-size: 1.5rem;
    content: "☃";
    padding-right: 5px;
  }
  .item:nth-child(2)::before {
    font-size: 1.5rem;
    content: "☎";
    padding-right: 5px;
  }
  .item:nth-child(3)::before {
    font-size: 1.5rem;
    content: "❆";
    padding-right: 5px;
  }
}

아이폰 S5
갤럭시 S5

728x90