Menu / CSS3 Responsive Navigation

Asked

Viewed 33 times

1

I’m having trouble creating a responsive menu/navigation below the code Html5 and css3.

As it should be:

inserir a descrição da imagem aqui

Could you tell me where the mistake is, please.

- HTML5:

    <nav>

        <a href="#"> TURISMO DIGITAL </a>

        <ul>
            <li> <a href="#sobre"> Sobre </a> </li>
            <li> <a href="#servicos"> Serviços </a> </li>
            <li> <a href="#portfolio"> Portfólio </a> </li>
            <li> <a href="#contato"> Contato </a> </li>             
        </ul>

    </nav>

- CSS3

nav{
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #4d4d4d;
}
nav > a {
    /* O filhos diretos de 'a' será estilizado, os demais não. */
    text-decoration: none;
    color: #f1f1f1;
    font-size: 28px;
    font-weight: bold;
    font-family: 'Facifico', 'serif';
}
nav ul{
    padding: 0;
    margin: 0;
    flex-direction: column;
    align-items: center;
    width: 100%;
}
nav ul li{
    text-align: center;
    width: 100%;
    padding: 1%;
}
nav ul li a{
    display: inline-block;
    padding: 10px 0;
    width: 100%;
    text-decoration: none;
    color: #f1f1f1;
}
nav ul :hover {
    background-color: #a4a4a4;
}

@media screen and (min-width: 768px) {
    nav{
        flex-direction: row;
        justify-content: space-around;
    }
    nav ul{
        flex-direction: row;
        width: 70px;
    }
}
  • Hi, do you make use of any front-end framework? Bootstrap, Foundation..... for example...

1 answer

0


Your CSS had several little problems that were preventing the nav to behave as expected, you had put a width from 70px to 70px UL and 100% for the LI, in addition to the classes inside and outside the @media were not hitting right and had to adjust and remove some property and put some other...

inserir a descrição da imagem aqui

Take a look at the code of the image above and when doubt comments there.

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #4d4d4d;
}

nav > a {
    /* O filhos diretos de 'a' será estilizado, os demais não. */
    text-decoration: none;
    color: #f1f1f1;
    font-size: 28px;
    font-weight: bold;
    font-family: 'Facifico', 'serif';
}

nav ul {
    box-sizing: border-box;
    padding: 10px;
    margin: 0;
    flex-direction: column;
    align-items: center;
    width: 100%;
    display: flex;
    list-style: none;
    justify-content: center;
    font-family: Arial, Helvetica, sans-serif;
    text-transform: uppercase;
}

nav ul li {
    text-align: center;
    /* width: 100%; */
    /* padding: 1%; */
}
nav ul li:not(:last-child) {
    margin-right: 10px;
}

nav ul li a {
    display: inline-block;
    padding: 10px 0;
    width: 100%;
    text-decoration: none;
    color: #f1f1f1;
}

nav ul li:hover {
    background-color: #a4a4a4;
}

@media screen and (min-width: 768px) {
    nav {
        flex-direction: row;
        justify-content: space-around;
    }

    nav ul {
        flex-direction: row;
        width: 50%;
        justify-content: flex-end;
    }
}
<nav>

    <a href="#"> TURISMO DIGITAL </a>

    <ul>
        <li> <a href="#sobre"> Sobre </a> </li>
        <li> <a href="#servicos"> Serviços </a> </li>
        <li> <a href="#portfolio"> Portfólio </a> </li>
        <li> <a href="#contato"> Contato </a> </li>
    </ul>

</nav>

Browser other questions tagged

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