코딩기록

html/css 3depth 네비게이션 메뉴 / 세로 아코디언 메뉴 본문

프론트

html/css 3depth 네비게이션 메뉴 / 세로 아코디언 메뉴

뽀짝코딩 2024. 10. 29. 16:21
728x90

html 기본구조 

ul > li > a + ul > li > a + ul 

 

● aria-expanded="false"

스크린리더 사용자에게 하위항목이 접혀있는지 펼쳐졌는지 알려주는 속성

펼친 상태 : true

접은 상태: false

 

 

● aria-conttols="food"  /  id

유니크한 id값을 식별해 컨트롤하는 속성 

 

2depth ul에 id="food"

이 2depth ul을 컨트롤하는 버튼(a태그)에 aria-conttols="food"

aria-controls="food"가 id="food"를 컨트롤,

2depth 의  aria-controls="fruits"  =>  3depth의  id="fruits" 를 컨트롤.

 
  <nav class="navigation">
    <h2 class="sr-only">전체 메뉴 리스트</h2>
 
    <!-- 1depth -->
    <ul class="navigation__list dep1-ul">  
      <li class="dep1-li">
        <a class="dep1-link arrow" id="clothes" role="button" aria-expanded="false" aria-controls="food">
          <span class="ico-clothes"></span>식품
        </a>
 
        <!-- 2depth -->
        <ul class="dep2-ul " id="food">
          <li class="dep2-li">
            <a class="dep2-link arrow" href="#clothes" role="button" aria-expanded="false" aria-controls="fruits">과일</a>
           
            <!-- 3depth -->
            <ul class="dep3-ul" id="fruits">
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">사과</a>
              </li>
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">바나나</a>
              </li>
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">키위</a>
              </li>
            </ul>
            <!-- //3depth -->
 
          </li>
        </ul>
        <!-- //2depth -->
     
      </li>
    </ul>
    <!-- //1depth -->
 
  </nav>
 

 

 

[ html ] 전체코드

<body>
  <nav class="navigation">
    <h2 class="sr-only">전체 메뉴 리스트</h2>
    <ul class="navigation__list dep1-ul">
      <!-- 1depth -->
      <li class="dep1-li">
        <a class="dep1-link arrow" id="clothes" role="button" aria-expanded="false" aria-controls="food">
          <span class="ico-clothes"></span>식품
        </a>
        <!-- 2depth -->
        <ul class="dep2-ul " id="food">
          <li class="dep2-li" >
            <a class="dep2-link arrow" href="#clothes" role="button" aria-expanded="false" aria-controls="fruits">과일</a>
            <!-- 3depth -->
            <ul class="dep3-ul" id="fruits">
              <li class="dep3-li" >
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">사과</a>
              </li>
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">바나나</a>
              </li>
              <li class="dep3-li" >
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">키위</a>
              </li>
            </ul>
          </li>

          <!-- 2depth -->
          <li class="dep2-li">
            <a class="dep2-link" href="#clothes" role="button">유제품</a>
            <!-- 3depth -->
            <ul class="dep3-ul">
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">우유</a>
              </li>
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">치즈</a>
              </li>
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">요거트</a>
              </li>
            </ul>
          </li>

          <!-- 2depth -->
          <li class="dep2-li" >
            <a class="dep2-link" href="#clothes" role="button">야채</a>
            <!-- 3depth -->
            <ul class="dep3-ul">
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">당근</a>
              </li>
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">양배추</a>
              </li>
              <li class="dep3-li">
                <a class="dep3-link" href="#clothes" role="button" tabindex="-1">오이</a>
              </li>
            </ul>
          </li>
        </ul>
      </li>

      <!-- 1depth -->
      <li class="dep1-li">
        <a class="dep1-link" href="/">
          <i class="ico-beauty"></i>화장품
        </a>
      </li>
      <li class="dep1-li">
        <a class="dep1-link" href="/">
          <i class="ico-book"></i>도서
        </a>
      </li>
      <li class="dep1-li">
        <a class="dep1-link" href="/">
          <i class="ico-sports"></i>스포츠
        </a>
      </li>

    </ul>
  </nav>
</body>

 

 

 

 

[ html ]

 

 

 

[ css ]

/* ---------------------------------------------- */
/* 내비게이션                                        */
/* ---------------------------------------------- */
.navigation {
  margin: 0rem 45rem 5.1rem;
  width: 54rem;
  height: 50rem;
}

.navigation__inner {
  position: relative;
  width: 54rem;
  height: 100%;
  border-top: 1px solid var(--color-gray-100);
  box-shadow: 0 4px 4px var(--color-opacity-20);
}

/* 내비게이션 리스트 ul 배치 */
.navigation__inner .dep1-ul {
  font-size: 1.2rem;
  position: absolute;
  top: 0;
  height: 100%;
  padding: 1rem 0.5rem;
}

/* 1,2depth / 2,3depth 구분선 */
.navigation__inner .dep2-ul,
.navigation__inner .dep3-ul {
  position: absolute;
  top: 0;
  left: 18rem;
  padding: 1rem 0.5rem;
  width: 100%;
  height: 100%;
}



/* 네이게이션 js  */
/* 1. ul 숨기기 */
.navigation,
.dep2-ul,
.dep3-ul {
  display: none;
}

/* 2. 마우스카테고리 접근시
    네비게이션 메뉴depth 펼쳐짐
*/
.is--active.navigation,
.is--active.dep2-ul,
.is--active.dep3-ul {
  display: block;
}

.dep1-link.is--active,
.dep1-link:focus,
.dep2-link.is--active,
.dep2-link:focus {
  color: var(--color-blue-600);
  font-weight: 700;
  background: url(../../assets/icon/more-right-active.svg) no-repeat 95% 50%;
}

.dep3-link:hover,
.dep3-link:focus {
  color: var(--color-blue-600);
  font-weight: 700;
  text-decoration: underline;
}



/* 내비게이션 리스트 li */
.ico-clothes {
  color: var(--color-blue-600);
}

.navigation__inner li .arrow {
  font-weight: 700;
  color: var(--color-blue-600);
}


.navigation__list .dep1-li {
  width: 18rem;
  height: 3rem;
  gap: 4px;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.navigation__list .dep1-link {
  display: flex;
  padding: 0.5rem 0rem 0.5rem 2rem;
  width: 15rem;
  align-items: center;
  gap: 4px;
}

.navigation__list .dep2-li,
.navigation__list .dep3-li {
  display: inline-block;
}

.navigation__list .dep2-link,
.navigation__list .dep3-link {
  display: block;
  padding: 0.5rem 0rem 0.5rem 2rem;
  width: 15rem;
}
/* 그림자 라인 */
.navigation__inner .dep2-ul::before,
.navigation__inner .dep3-ul::before {
  content: '';
  position: absolute;
  border-top: 1px solid var(--color-gray-100);
  width: 0.1rem;

  /* 100%에서 위,아래 1rem씩 뺀 2rem을 제외한 height크기
  height: calc(100% - 2rem);*/
  height: 100%;
  top: 0;
  box-shadow: -1px 0 2px var(--color-opacity-20);
}

 

 

 

 

 

 

 

 

 

 

 

반응형
Comments