2017-12-19 3 views
2

나는 네비게이션 HTML을 가지고있어 반응 형으로 만들고있다. 햄버거 메뉴를 1050px 미만의 화면 크기로 표시하는 데 성공했으며 메뉴를 켜고 끕니다. 문제는 화면을 크게 만들기 전에 햄버거 메뉴를 닫지 않으면 nav 메뉴가 display : none 모드로 고정되어 표시되지 않는다는 것입니다. 그래서 탐색이 갑자기 사라지는 것처럼 보입니다. 나는 보통 CSS가 더 큰 화면 크기에 종사 할 것이라고 생각했지만 속성은 스크립트에 설정되어 있기 때문에 남아있을 것입니다. 누구든지이 문제를 해결할 수있게 도와 줄 수 있습니까? 나는 반응이 빠른 디자인에 상당히 익숙하다.더 큰 화면 크기에서 사라지는 내비게이션

HTML :

<nav> 
<div class="navigation"> 
    <a href="/index.html"> <img class="nav-img" src="/incl/image.png"> </a> 

    <button id="mobile" type="button" onclick="toggleFunction()"> 
      <img src="/incl/menu.png" width="35px" height="35px" alt="menu"> 
    </button> 

    <ul id="nav-list"> 
     <li> <a href="/proposer/">Proposer</a> </li> 
     <li> <a href="/cda/">Archive</a> </li> 
     <li> <a href="/ciao/">Data<br/>Analysis</a> </li> 
     <li> <a href="/cal/">Instruments and<br/>Calibration</a> </li> 
     <li> <a href="/public/">For The<br/>Public</a> </li> 
    </ul> 
</div></nav> 

<script> 
    function toggleFunction() { 
     var x = document.getElementById('nav-list'); 

     if (x.style.display === 'block') { 
      x.style.display = 'none'; 
     } else { 
      x.style.display = 'block'; 
     } 
    } 
</script> 

CSS : 이것은 #nav-list 요소 toggling a class입니다 해결하기 위해

#nav-list { 
list-style-type: none; 
padding-top: 30px; 
padding-right: 20px; 
margin: 0px; 
overflow: hidden; 
display: inline-table; 
float: right; 
} 

#nav-list li { 
display: table-cell; 
vertical-align: middle; 
padding: 0px 15px; 
margin: 0px; 
text-align: center; 
line-height: 110%; 
font-size: 1.3em; 
font-family: Helvetica, Arial, sans-serif; 
font-weight: 400; 
} 

#mobile { 
display: none; 
} 

@media only screen and (max-width: 1050px) { 
.nav-img { 
    margin: 0px 5px 5px 5px; 
} 

#mobile { 
    display: inline; 
    float: right; 
    background-color: transparent; 
    border: 1px solid #333; 
    border-radius: 5px; 
    margin: 10px 10px 10px 0px; 
    padding: 5px; 
} 

#nav-list { 
    list-style-type: none; 
    margin: 0px; 
    padding: 0px; 
    overflow: hidden; 
    display: none; 
    float: none 
} 

#nav-list li { 
    display: block; 
    text-align: center; 
    margin: 10px 0px 10px 0px; 
    line-height: 110%; 
    font-size: 1em; 
} 

답변

0

가장 간단한 방법.

이 변경으로 모바일 미디어 쿼리의 CSS에서만 클래스가 의미를 가지며 #nav-list에서 display: block으로 변경됩니다. 이 클래스는 토글 여부에 관계없이 1050 픽셀 이상의 화면에는 영향을 미치지 않습니다.

function toggleFunction() { 
 
    var x = document.getElementById('nav-list'); 
 
    x.classList.toggle('show'); 
 
}
#nav-list { 
 
    list-style-type: none; 
 
    padding-top: 30px; 
 
    padding-right: 20px; 
 
    margin: 0px; 
 
    overflow: hidden; 
 
    display: inline-table; 
 
    float: right; 
 
} 
 

 
#nav-list li { 
 
    display: table-cell; 
 
    vertical-align: middle; 
 
    padding: 0px 15px; 
 
    margin: 0px; 
 
    text-align: center; 
 
    line-height: 110%; 
 
    font-size: 1.3em; 
 
    font-family: Helvetica, Arial, sans-serif; 
 
    font-weight: 400; 
 
} 
 

 
#mobile { 
 
    display: none; 
 
} 
 

 
@media only screen and (max-width: 1050px) { 
 
    .nav-img { 
 
    margin: 0px 5px 5px 5px; 
 
    } 
 

 
    #mobile { 
 
    display: inline; 
 
    float: right; 
 
    background-color: transparent; 
 
    border: 1px solid #333; 
 
    border-radius: 5px; 
 
    margin: 10px 10px 10px 0px; 
 
    padding: 5px; 
 
    } 
 

 
    #nav-list { 
 
    list-style-type: none; 
 
    margin: 0px; 
 
    padding: 0px; 
 
    overflow: hidden; 
 
    display: none; 
 
    float: none 
 
    } 
 

 
    /* show navigation based on class */ 
 
    #nav-list.show { 
 
    display: block; 
 
    } 
 

 
    #nav-list li { 
 
    display: block; 
 
    text-align: center; 
 
    margin: 10px 0px 10px 0px; 
 
    line-height: 110%; 
 
    font-size: 1em; 
 
    } 
 
}
<nav> 
 
    <div class="navigation"> 
 
    <a href="/index.html"> <img class="nav-img" src="/incl/image.png"> </a> 
 

 
    <button id="mobile" type="button" onclick="toggleFunction()"> 
 
      <img src="/incl/menu.png" width="35px" height="35px" alt="menu"> 
 
    </button> 
 

 
    <ul id="nav-list"> 
 
     <li> <a href="/proposer/">Proposer</a> </li> 
 
     <li> <a href="/cda/">Archive</a> </li> 
 
     <li> <a href="/ciao/">Data<br/>Analysis</a> </li> 
 
     <li> <a href="/cal/">Instruments and<br/>Calibration</a> </li> 
 
     <li> <a href="/public/">For The<br/>Public</a> </li> 
 
    </ul> 
 
    </div> 
 
</nav>

+0

일했다! 고맙습니다 – got2b

관련 문제