Open and close menu button

Asked

Viewed 66 times

0

Good evening guys, I’m new to programming and I’m trying to put on my web page an open and close menu button. I apologize if it’s repeated, because I couldn’t find one that looked like mine, so I posed that question. The arch used for the button is an image.

The following is happening on my website:

Essa é a tela do botão quando estou no modo responsivo de minha pagina

This screen above is the button when I am in the responsive mode of my page

When I click on the button it appears the menu, but does not change the close button.

inserir a descrição da imagem aqui

This is the screen that appears when I click the button, it had to change the button to: inserir a descrição da imagem aqui

After clicking the close button, it would have to go back to the first screen.

The open and close button is a single file that is changed to position through the background-position

follow the file image. inserir a descrição da imagem aqui

Below is my html, css and Javascript code made so far:

HTML structure of the button:

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="css/normalize.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="css/estilo.css">
</head>
<body>
<div class="interface">
      <header class="cabecalho">
        <nav class="menu-principal">  
          <button class="menu-principal__btn menu-principal--fechado" onclick="clicar()">Abrir menu</button>   
          <ul class="menu-principal__lista">  
            <li><a class="menu-principal__item" href="index.html">Quem sou eu</a></li>
            <li><a class="menu-principal__item" href="empresas.html">Experiência Profissional</a></li>
            <li><a class="menu-principal__item" href="historico-formacao.html">Histórico & Formação</a></li>
            <li><a class="menu-principal__item" href="especializacoes.html">Especializações</a></li>
            <li><a class="menu-principal__item" href="idiomas-certificacoes.html">Idiomas & Certificações</a></li>
          </ul>  
        </nav> 
</div> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>

Follow the CSS button

.menu-principal{
    margin: 0;
}

.menu-principal__lista{
    transition: margin 200ms ease-out;
}

.menu-principal__item{
    transition: all 200ms ease-out;
    height: 20px;
}

.menu-principal__btn{
    display: block;
    width: 50px;
    height: 50px;
    text-indent: -9999px;
    background-image: url('../img/menuprincipal-btn-bg.png');
    background-repeat: no-repeat;
    background-position: -48px 7px;
    background-color: whitesmoke;
    border-color: rgb(35, 65, 145);
    border-style: solid;
    border-radius: 5px;
    cursor: pointer;

    position: absolute;
    top: 15px;
    right: 15px;
}

li{
    text-decoration: none;
    list-style: none;
    font-weight: bold;
    padding: 5px;
    padding-bottom: 5px;
    font-size: 18px;
}


@media (max-width: 767px){
    .menu-principal__btn{
        background-position: 5px 5px;
    }

    .menu-principal--fechado{
        background-position: -48px 7px;
    }    

    .menu-principal__lista{
        margin: 0;
    }

    .menu-principal__item{
        margin: 0;
        height: 0;
        display: none;
    }
}

Follow the Javascript code - I used jQuery - I don’t know much about jQuery, how I couldn’t make it work, so I wrapped the content inside a function and called this function in the HTML button.

function clicar(){

    $( ".menu-principal__item").toggle(function() {
        $(".menu-principal--fechado").show();
        $(".menu-principal--btn").show();
     }, function() {
        $(".menu-principal__btn").show();
     });
}

If anyone can help me in what I’m missing.

  • ola Fabricio, if it is to study css is good, but if it is not that pq not use something ready that already does it and is well used in the market? can not use bootstrap who already does that?

  • Good Ricardo. Good morning. I had not thought and nor knowledge that in bootstrap it was possible to do this. Have some tutorial how to do?

  • in the bootstrap website has it all, see examples of navbar and try to increase/reduce the size of the browser

  • Good evening Ricardo, I managed to solve using the bootstrap. Thank you so much for your help.

  • Have you ever experienced anything like bootstrap? If you see on the page, in responsive mode, this is solved for you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.