Two Different Horizontal Menus

Asked

Viewed 915 times

3

I’m creating two horizontal menus on the same page with different settings and so I used a class in each of them.

I’m not getting one of these menus to get the one-color box on have

What I did was give one padding to each of the menu items so that when the mouse is passed it will be that color.

I gave a yellow color to show the default state and another yellow, lighter, when passing the mouse.

In short: The problem is that when passing the mouse the light yellow color does not occupy all the yellow that is in premanence - http://jsfiddle.net/Lyu65/

My current code:

ul.nav{
    font-family: globerthin, Verdana, Arial, Geneva, sans-serif;
    list-style-type: none;
    margin-top: 50px;
    }
ul li.nav{
    display: inline;
    background-color: yellow;
    color: black;
    margin-left: 20px;
    padding-left: 25px;
    padding-top: 25px;
    padding-right: 25px;
    padding-bottom: 25px;
    font-size: 125%;
    font-weight: bold;
    }
.nav a:link{
    color: black;
    text-decoration: none;
     }
.nav a:visited {
    color: black;
    text-decoration: underline;
}
.nav a:hover{
    background-color: #faf6eb;
    text-decoration: none; 
    }
.nav a:active{
    color: black;
    text-decoration: underline; 
    }

<ul class="nav">        
<li class="nav"><a href="index.html#equipamentos" title="Navegar para Eqipamentos">EQUIPAMENTOS</a></li>
<li class="nav"><a href="index.html#actividades" title="Navegar para actividades">ACTIVIDADES</a></li>
<li class="nav"><a href="index.html#duvidas" title="Navegar para dúvidas técnicas">D&Uacute;VIDAS T&Eacute;CNICAS</a></li>
<li class="nav"><a href="index.html#reparar" title="Navegar para ás reparações de equipamentos">REPARA&Ccedil;&Atilde;O DE EQUIPAMENTO</a></li>
<li class="nav"><a href="index.html#usados" title"Navegar para usados">USADOS</a></li>
<li class="nav"><a href="index.html#blogue" title="Navegar para ao blogue">BLOGUE</a></li>
  • Post your HTML, but from what you reported, if there are two menus different by setting the same class for both menus it will be equal. Assuming I’m right, you either work with unique Ids, one for each menu and style them individually or a different class for each, but still style them individually. If there are properties with shared styles, you can group them in the same rule.

  • No Bruno. I created each class with a different attribute. See the html I edited the question.

  • Either you put only part of the code or really nay, you used the same class for all elements (they all have class="nav"). Worse! You gave the same class both for the list (<ul>) how much for your items (<li>).

  • So how should I do?

2 answers

1

The problem was best clarified only in the comments then, although this answer is not in the format of a horizontal menu, it still solves the problem as stated in response of the author himself.

Throughout the comments exists a link for the same solution but considering the format inline.


At the request of the author a very simple demonstration:

HTML

<ul id="menu1">
    <li><a>Item #1</a></li>
    <li><a>Item #2</a></li>
    <li><a>Item #3</a></li>
</ul>

<ul id="menu2">
    <li><a>Item #1</a></li>
    <li><a>Item #2</a></li>
    <li><a>Item #3</a></li>
</ul>

CSS

#menu1, #menu2 {
    border: 1px solid #000;
    list-style-type: none;
    margin: 0;
    padding: 0;
    width: 250px;
}

#menu1 li, #menu2 li {
    padding: 5px;
}

#menu1 li {
    background-color: #FFFF00;
}

#menu1 li:hover {
    background-color: #FFFF4D;
}

#menu2 li {
    background-color: #FF0000;
}

#menu2 li:hover {
    background-color: #FF4D4D;
}

Demo at Jsfiddle

See what has been done and compare with your current code.

We have two menus, but each with a different ID, so whatever is applied to one of them, if the rule is not being applied to both, will not be applied to the other.

When the mouse passes through the items of each selector li:hover is fired and the background color shift.

  • Bruno you did not understand my doubt. I just put in this question one of the horizontal menus. I just mentioned that I have two horizontal menus on the page so you know why I used a class. What you did with this code I did in mine. The problem is that the backgroud-color of a Hover only fills the content of each text and not the padding.

  • I understood correctly. It turns out that by your CSS you define the change of background in the Hover of <a>, but the padding is in the <li>. That way, the change will only happen in the background of the <a> not on the entire line. The way I demonstrated the switch occurs when the mouse is over the entire line, no matter what part of it. See in the second revision of the code, in the second menu, how many rules the most would be necessary to keep the Hover happening at the <a>. Everything is commented on ;)

  • But I want to make the menu "inline" and not in block. After cm I am beginner it becomes difficult to understand what you wrote. It’s all very different from what I wrote. I appreciate the help and it is noted that you understand the subject but I asked you to try to teach correctly with a closer approach.

  • Well, from the newsroom, one would imagine that the horizontal menu is already in operation. I’m working with information, if I don’t have a clear definition of the problem, I can’t help you. See if it’s that who needs

  • Do this, take the code I put in the topic and change this code that works. Use only one menu, not two. And use that code. This helps, really. Once again the problem is only in "the Hover" seems simple but apparently it is not.

  • Note that when you hover the mouse, the lighter yellow does not occupy the whole box. I want you to occupy it. How do you do that? - http://jsfiddle.net/brunoaugusto/3PdM5/3/

  • Thus? If it is enough that the color change occurs in the Hover of <ul> instead of <li> or even of <a>. But I really hope it’s not that because doing it pretty much defeats the whole purpose of a Hover.

  • I’m sorry about my last message. I tried to use that site that’s in my last message but I couldn’t. I’ve now managed to use the jsfiddle site. If you go to the link I show in this comment there is a part of the menu I want to do on my site. What’s the problem? Once again, when you pass the mouse through the menus, the color changes. The problem is that this colour does not occupy the whole yellow box - http://jsfiddle.net/Lyu65/

  • It seems the case is quite what I demonstrated in the penultimate comment, with the fourth revision

  • I don’t know if it is or not because I didn’t understand anything. I presented a code in a simple way. It may contain errors but it is the simplest code. You presented a code more summarized. Well, as I’m still taking the first steps, I couldn’t understand. Anyway I have already managed to do what I want - http://jsfiddle.net/Lyu65/1/ Thank you, however, for your help.

  • I edited the Disclaimer because now it seems that the answer is again valid.

Show 6 more comments

1


I found out where the problem is.

In the hover i put a:houver after the color, actually I want to apply the color not to the a but yes to the li.

So it should stay that way:

#navt li:hover{
    background-color: #faf6eb;
}

Instead of:

#navt a:hover{
    background-color: #faf6eb;
}
  • @ Bruno Augusto had the resolution in his example code in comments above the problem is that it did not go straight to the point. So I had not seen that the problem had been solved. It was necessary to read more things to get there. Thanks for the help.

  • I’ll be commenting on this answer too just to have one demo link reference. Do not forget to mark an answer as solved, be mine (which although not having the menu inline contains the correct repsosta) or yours, if you think it is due.

  • Although your answer solves the problem of the question and is pioneering why even you could not answer directly to my question. I had to go back to school to find the answer. After knowing the answer I analyzed your answer and then I saw that you had the correct answer in the middle of so much information. I appreciate your help but try to be more direct in your answers. Thank you.

Browser other questions tagged

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