Create Menu DropDown

1

Can anyone help me? I would like to make this menu a dropdown menu, but I am not yet aware of it, and I would like to ask for help.

// CSS

nav#mainnav ul {
    padding: 0;
    margin: 0;
    list-style: none;
}

nav#mainnav li {
    padding:0;
    border-bottom: 1px solid #99C581;
    border-top: 1px solid #6FAB4F;
}

nav#mainnav li.selected-item  {
    border-bottom:none;
}

nav#mainnav li.selected-item a,
nav#mainnav li.selected-item a:hover {
    color:#80B763;
    font-weight:bold;
    background: #fff;
}

nav#mainnav li a:hover {
    background:#669D48;
    color: #fff;
    text-decoration:none;
}

nav#mainnav li a {
    color: #f0f0f0;
    display: block;
    padding: 15px 17px;
    text-align: right;
    font-weight:  bold;
    text-decoration: none;
}

// HTML

<nav id="mainnav">
  <ul>
    <li class="selected-item"><a href="index.html">Home</a></li>
    <li><a href="#">Exemplo 1</a></li>
    <li><a href="#">Exemplo 2</a></li>
    <li><a href="#">Exemplo 3</a></li>
    <li><a href="#">Exemplo 4</a></li>
   </ul>
</nav>
    
asked by anonymous 20.02.2016 / 18:53

5 answers

1

You can start by changing the HTML structure of your menu, not that it is not possible to do with this structure, but it would be better to work differently. This is just an example and you need to make the modifications according to your needs.

#mainnav ul{
  list-style: none;
}

#mainnav ul li{
  padding:10px 15px;
  background:#000000;
}

.wrapper-menu{
  position:relative;
}

.dropdown{
  position:absolute;
  left:0;
  display:none;
}


.wrapper-dropdown:hover > .dropdown{
  display:block;
}
<nav id="mainnav">
  <ul class="wrapper-menu">
    <li class="wrapper-dropdown">
      <a href="index.html">Home</a>
      <ul class="dropdown">
        <li><a href="#">Exemplo 1</a></li>
        <li><a href="#">Exemplo 2</a></li>
        <li><a href="#">Exemplo 3</a></li>
        <li><a href="#">Exemplo 4</a></li>
      </ul>
    </li>
   </ul>
</nav>

This HTML structure for dropdown can hold multiple dropdowns, with this structure you currently use you could only put a few options

    
20.02.2016 / 19:29
0

@Renan you asked about the css ??

I will try to explain in a detailed way:

First you should notice that your code is inside a nav, okay you told the navigator semantically that here inside the nav will be your navigation session ok, soon after you put an ul and inside that ul, you put 5 li (s);

Explaining how you could style this in css;

Keep in mind that you begin to style the parent,

ul.menu {
      list-style:none; //Repara, quero remover as bolinhas das li(s)
}

Now you'll stylize your links;

/*Configura todos os links do menu*/
ul.menu a {
      text-decoration:none; //Quero remover o sublinhado da linha
      color: #fff; //cor do link
      display:block; //faz com que o elemento HTML seja renderizado como bloco, aqui acontece a magica;
}


/*Faz os <li>s ficarem na horizontal*/
 ul.menu > li {
       //Perceba que não quero estilizar todas as lis, somente as que são filhos direto da minha ul pai;
       //Quero que as li(s) ficam deitadas ex:Home Contact  AboutMe  etc
       float:left; //irão flutuar a esquerda
       position:relative; //A posição relativa ao pai
 }

Explanation about relative and absolute positioning of css

/*Configurar os links do menu principal*/
ul.menu > li > a {
     position: relative;
     padding: 20px;
     margin: 0 5px;
}

/*Configurar o efeito ao clicar o mouse no link*/
ul.menu > li > a:active{
    top: 3px;
    left: 2px;
    box-shadow: 0px -2px 0px #009900;
    font-size: 12px;
    width: 150px;
    text-align: center;
}

/*Configurar o fundo do menu principal quando o mause passar em cima do meu link*/
ul.menu > li > a:hover{
    background: #009900;
}

If you had within your li (s) another ul:

/*Mostrar o submenu no evento do mouse hover*/
ul.menu > li:hover > ul.submenu{
    display: block;
}

The rest of the sub-menu settings are similar, so here you have the code, it will be easy to have the logic of how to build a drop down menu, it is connected that there are hundreds of ways to do this, the interesting thing would be you try to understand the selector, properties, values and how to declare themselves, how the css hierarchy works is not easy at first to get bored in this, but practice leads to perfection. I hope I have helped in some way.

    
20.02.2016 / 22:40
0

Do you need to be this example up there? if not, there are several tutorials on the internet, such type link

I made one using this link as an example. check out link

    
22.02.2016 / 16:44
0

Hello, Bootstrap came to make our life easier with css. it standardizes the entire css framework and has on this site has a documentation with almost everything ready! :)

Simply associate one of the three Tags in the Head by referencing the css, jQuery library and compiled version, all three in this order:

<!DOCTYPE html>
<html lang="en-US">
<head>

<!--Obedeça esta estrutura de diretório, primeiramente o Bootstrap css -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- A Biblioteca jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><!--OJavascriptcompilado--><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div>
  <nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">Seu Site</a>
    </div>
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Home</a></li>
      <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown" href="#">Página 1
        <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a href="#">Página 1-1</a></li>
          <li><a href="#">Página 1-2</a></li>
          <li><a href="#">Página 1-3</a></li>
        </ul>
      </li>
      <li><a href="#">Página 2</a></li>
      <li><a href="#">Página 3</a></li>
    </ul>
  </div>
</nav>
</div>

</body>
</html>
    
11.05.2017 / 04:51
-1

See Dinamic Drive . There you have many things ready, and you can customize.

    
22.02.2016 / 18:47