Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
HTML/CSS Designing a responsive website. An onclick attribute won't function

I'm trying to create a responsive design for a practice website. The situation is that the below menu-icon image is only displayed while width is less than 701 px. So it does that fine. But the problem is that, when menu-icon image is displayed, screen width less than 701 px, I click on the image and nothing happens. The onclick attribute "togglemenu()" does not seem to function. Can someone help please? This is a live site:

https://moortje.github.io/HTML-CSS-Project-Bro-Code/

The menuList and menu-icon in question are at the very bottom.

Here is an HTML snippet.

<ul id="menuList">
    <li><a href="">CSI</a></li>
    <li><a href="">CHP</a></li>
    <li><a href="">HCSS</a></li>
    <li><a href="">JS</a></li>
</ul>
       
<img src="moortje2.png" class="menu-icon" onclick="togglemenu()">
    
<script type="text/javascript">
        
    var menuList = document.getElementById("menuList");
       
    menuList.style.maxHeight = "0px";
      
    function togglemenu(){
        
        if (menuList.style.maxHeight == "0px") {
            menuList.style.maxHeight = "130px";
        }

        else{
            menuList.style.maxHeight = "0px";
            }
    }
        
</script>

Here is a CSS snippet.

.menu-icon{
            width: 25px;
            cursor: pointer;
            display: none ;
           }

@media only screen and (max-width: 700px){
        .menu-icon{
            display: block;
        }
    
        #menuList{
            overflow: hidden;
            transition: 0.5s;
        }
}
about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

The problem is that you are setting max-height and max-width

Changing those properties doesn’t change the size of the element, only what its max bounds are.

Use width and height instead.

about 4 years ago · Santiago Trujillo Relatório

0

It's appear at the top of the page because of position: absolute

about 4 years ago · Santiago Trujillo Relatório

0

Well I went through the code and find out that togglemenu function is working properly and its even opening the menu. But you have given position absolute to ul tag and when you click on toggle image. It opens menu but at the top of page.

So click on image and scroll up to top and you will going to see your menu. You just have to adjust its position to open it below toggle menu button/image.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda